How Can I Determine When a "For Each Item" Action is complete in Flow Designer

cwolfe01
Giga Guru

In Flow Designer, I have a For Each Item action that looks through a list of computers. In that section, I'm generating SCTASKS for each item, and I want to close the associated RITM and REQ only after each item has been processed. How could I determine the number of items in my For Each Item action so I could include an IF statement that says if my counter variable equals the number of items in the For Each Item action, then do a certain action? 

 

I have a Set Flow Variables action at the beginning of my flow, and I'm using the following script to count the number of items in my asset_tags list variable.

var assets = fd_data.trigger.request_item.variables.asset_tags.length;
return assets;

Screenshot 2023-10-02 174611.png

My thought process here is that using the .length method would count the number of entries in the asset_tags variable, and that I could return that value for the Flow Variable, but there is no runtime value when I test my flow.

1 ACCEPTED SOLUTION

cwolfe01
Giga Guru

I've got the solution. All I had to do was move the subflow used to close the RITM & REQ on the same level as the For Each Item action

View solution in original post

3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @cwolfe01 

If .length didn't work, you can try an alternate approach.

1. Create a flow variable called counter of type integer.

2. Before for each set the counter variable to 0 using flow logic -> Set flow variable

IMG_20231003_033929.jpg

 

 3. Now, inside for each increment the counter variable value by 1, to do this set flow variable value using inline script.

return fd_data.flow_var.counter + 1;

IMG_20231003_033956.jpg

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

How would I determine if my counter variable matches the number of iterations my loop has?

cwolfe01
Giga Guru

I've got the solution. All I had to do was move the subflow used to close the RITM & REQ on the same level as the For Each Item action