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.

1 ACCEPTED SOLUTION

Yousaf
Giga Sage

Hi Suvro,
You might have to create a custom action to make this work. 


***Mark Correct or Helpful if it helps.***

View solution in original post

6 REPLIES 6

Tanushree Maiti
Tera Patron

Hi @suvro 

 

Refer this posts:

https://www.servicenow.com/community/developer-forum/ask-for-approval/m-p/3346756

Scripted Approvals in Flow Designer with Flow Variables

https://www.servicenow.com/community/developer-forum/flow-designer-catalog-workflow-approval-from-ea...

https://www.servicenow.com/community/itsm-forum/how-to-dynamically-assign-approvers-in-flow-designer...

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

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.