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

Yousaf
Giga Sage

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


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

Rafael Batistot
Kilo Patron

Hi @suvro 

 

May you use a List Collector in the Catalog Item and a For Each in the Flow.

This is the best and recommended approach.

 

Catalog Item

Create the variable as:

  • Type: List Collector
  • Reference: the appropriate approval table

A List Collector already returns a list of sys_ids, which Flow Designer treats as an Array.

 

Flow Designer

  • Use the catalog variable directly
  • Add a For Each action
  • Iterate over the List Collector values
  • Inside the loop, use Create Approval
    • Approver = current item from the loop
If this response was helpful, please mark it as Helpful and, if applicable, as Correct, this helps other users find accurate and useful information more easily.

Ankur Bawiskar
Tera Patron

@suvro 

check this for scripted flow approval

Scripted Approvals in Flow Designer with Flow Variables 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@suvro 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader