Postman Flows - For Loop - End of array processing


Apologies if this has already been asked but I cant see anything and I haven’t been able to figure it out myself. I thought I was making progress with it but the IF block and checking whether the array was populated was a dead end, or at least I didn’t know what I was doing!

My question is, if I have a list of records (3) being read in and a for loop to process each record, is there a way to specify at the end of the loop, to go do something else? In this example below, for each input record I call the MTS API. After the third and final call I want to call a different API to check the results of the previous 3 ‘MTS’ calls. Obviously, if there were 4 input records it would be after the 4th ‘MTS’ call etc…

Thanks in advance,

I’ve managed to get this working, but there has to be a better, cleaner way. I’ve added a record number to the input (1,2,3) then created a variable called recCount which is set to 3. In my for loop there is a check on recordNumber and recCount, when they’re equal, do the something else. Is there a better way?

Hi @chrisdoar

If you want to perform an action after all the records have finished looping, you can just put a collect block at the end which will wait until after the loop competes (the collect block will return a list of all the outputs of each iteration of the loop).

1 Like

Thank you again @flows-daniel for the advice. I’ll give that a go.

Kind regards,

@flows-daniel, I’ve added a collect block and it done exactly what I wanted. Much neater and more concise than I originally had. Thanks for your guidance again :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.