How to dnamically iterate object of array in flow designer subflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 07:05 PM - edited 05-19-2025 07:24 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 08:03 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 08:12 PM - edited 05-19-2025 08:13 PM
I get that. My question is understand on iterating in a sub flow given the object is an output from an action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 12:42 AM
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