BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  Is there an easy way to get an item out of a Name-Value Pair List?

    Posted Thu October 26, 2023 08:25 AM

    Hello,

    I have a UCA that is receiving a Name-Value Pair list.  Is there an easy way to retrieve an item with a particular name?

    For example, I want the value of the pair where Name = "Account Number" so I can assign it to a variable.

    I know I can iterate through the list, but was wondering if there was an easier way.

    Thanks!

    Tracy



    ------------------------------
    Tracy Green
    ------------------------------


  • 2.  RE: Is there an easy way to get an item out of a Name-Value Pair List?

    Posted Fri October 27, 2023 03:25 AM

    Hi Tracy

    Not sure if this is "easier" but here is an alternative way (works in a server-side script):

    tw.local.myVal = tw.local.myList.listToNativeArray().reduce(function (acc, cur, idx) {
        return (cur.name === "Account Number" ? cur.value : acc);
    });

    FYI, my team uses server file(s) that hold various utilities and your requirement would be satisfied by a function like this:

    Utils.findValueInList = function (list, valueProp, searchProp, searchValue) {
        if (list && list.length > 0) {
            for (var i = 0; i < list.length; i++) {
                if (list[i][searchProp] === searchValue) {
                    return list[i][valueProp];
                }
            }
        }
    };

    So your code would just call this function like so:

    tw.local.myVal = Utils.findValueInList(tw.local.myList, "value", "name", "Account Number");



    ------------------------------
    ZAFIRIS KERAMIDAS
    ------------------------------



  • 3.  RE: Is there an easy way to get an item out of a Name-Value Pair List?

    Posted Fri October 27, 2023 08:11 AM

    This works for what I need.  Thanks!

    Tracy



    ------------------------------
    Tracy Green
    ------------------------------