How to dnamically iterate object of array in flow designer subflow

Snehal13
Kilo Sage

The object(from output of action) is as below

{

"New": [],

"Open": [],

"Closed": []

}

 

Each element may or may not have array elements. Example : New may have 3 values and Closed may be empty and Open may have 1 array value 

 

I want to find which one (New/Open/Closed) has values and loop through them dynamically in my sub flow

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

Hi @Snehal13 ,

 

In Flow Designer, when all items are removed from an array variable, it can become null. 

 

1)Set a Default Empty Array:

Initialize your array variable with an empty array ([]) as the default value. This way, even if all items are removed, the variable retains an empty array instead of becoming null.

 

2)Use a String Variable with JSON

Alternatively, use a string variable to store your array in JSON format. For example, store the array as '[]'. When needed, parse this string back into an array using a script step. This method ensures the variable remains a string and doesn’t become null when empty.

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

I get that. My question is understand on iterating in a sub flow given the object is an output from an action.

Robert H
Mega Sage

Hello @Snehal13 ,

 

One idea would be to create a custom action with a script step that takes an object like you have described, and returns an array with all the values. Then you can plug that action into your flow and iterate over its output.

 

Example script:

var input = {
    "New": ['a', 'b'],
    "Open": ['c'],
    "Closed": []
};

var output = [];
for (var element in input) {
	output = output.concat(input[element]);
}

gs.info(JSON.stringify(output));

 

Result:

["a","b","c"]

 

Regards,

Robert