Loop through an array, and each iteration move to the next node

I was curious if the there was a method to have each loop iteration, continue onto the next workflow node. So if I have an array of 5 names, and the next node is to post them to slack, each iteration would fire a new message to slack. Currently it looks like the output from the loop is the array itself, not individual index values.

My test setup is to loop through an array, add a suffix to the array values, then send them individually to slack. However it's sending the array as one message.

I can work around this by creating a second loop that uses the Slack action.

while this works, If possible I'd rather not push a giant array between nodes and loop through each time, ideally I'd be able to sequentially pass the index/item through the next nodes, once completed go back to the loop. Is this possible?

Hello @Kovon and welcome back!

When working with loops in workflows I have been leaning heavily on the JS Code setup and creating functions to handle the different API/Resource events. Aside from being able to get a bit more insight with error handling, you can filter the loop results with the index values so that you can reference the giant array just once for the next stage of processing. Here is an example that is being developed in one of my current use cases:

sendPayload is the function I created to make the API call and I can try/catch in this case because of how the API responds with error data.

1 Like

Hey @Kovon! :wave:

I'll add just a little bit of context and my own two cents. There's nothing really wrong with two sequential loop blocks, but I agree that it could probably be more elegant. To @pyrrho's point, the solution is almost always functions.

Instead of thinking about an array of elements, write functions that instead handle just a single element. Then, all you have to do is invoke them from within the loop block and pass in value:

This is a super bare-bones implementation, but you can see that I've abstracted away most of the heavy-lifting into functions and am thus able to perform a series of complex operations on my data as I'm looping through it. In a single loop, nonetheless. This also allows for more effective error handling, which is what @pyrrho has highlighted.

I hope that helps!