How to set a flow variable of type array using a script

suvro
Mega Sage

Hi,

I am using a flow for a catalog item, where there is a variable which contains an object which has an array.

And I need to generate approvals dynamically based on the length of the array. 

So I though of creating a flow variable of array type and using set flow variable I will be able to parse that variable and set the variable with the array, but I do not see any option of wrting a script. The option appears for string type of variable. Any pointers will be appreciated thanks.

6 REPLIES 6

yashkamde
Mega Sage

Hello @suvro ,

 

You can create a custom action in which pass your array as input through flow.
And for generating dynamic approvals use this script for output..

 

(function execute(inputs, outputs) {

    var arr = inputs.approvalArray || [];

    if (arr.length > 0) {
        outputs.result = 'ApprovesAnyU[';
        for (var i = 0; i < arr.length; i++) {
            outputs.result += arr[i];
            if (i < arr.length - 1) {
                outputs.result += ',';
            }
        }
        outputs.result += "]";
    } else {
        outputs.result = 'No approvers provided';
    }

})(inputs, outputs);

 

You will get the output as (comma seperated sys_id's - directly passing into the Ask for approval action) :

ApprovesAnyU[5137153cc6112xxxxx00bbdxxxxxxx07,d1f6fd36c37xxxxxxxx275e40131d5]

 

If my response helped mark as helpful and accept the solution.