How does loop in workflow work?

I've created my first workflow and I think I'm doing something wrong with my loop.
What it should do:

  • Fetch list with trackingno's from Retool DB
  • loop through this list and for each trackingno get the status from UPS
  • for each trackingno, check the statuscode, if status = 011, kickoff api call, else kickoff other api call

For now it seems that it evaluates the checkStatus block only once and not for each trackingno
How to get this working?

Hey mbruijnpff,

Loop should return an array of results - for each value passed.

Do you mind expanding the JSON output to view the structure of the data and see if it passed only one value?
Assuming GetParcelTracking is an API call it might be worth adding await before the trigger so the requests do not time out due to some API limits.
image

From there we can work on pinpointing what is happening!

The loop is outputting an array with objects:
image

One object for each trackingno, so that seems to be ok.

How go go further and finish the workflow for each object? For delivered items something needs to be done and not delivered once will be polled another time.

In that case you need a branch to check if loop returns results and if it fits some of your additional criteria (i.e. loopTrackno.data.length>0). Then all you need to do is loop through "loopTrackno" results and do the desired action.

For the ones that need to be polled another time you can use the getTrackno and exclude the items present in loopTrackno and set the status or whatever you want it to do.

I've tried adding a branch after the loop, see my first post. If statuscode is 011 (delivered) it will doe something. else it should update the Retool DB with last polling time and current status, so it can be checked again later.

Did I use the branch wrong?

Now it seems that it is only evaluating the first object in the returned array

If I'm not mistaken Branch just represents a visual IF statement and it won't loop through the results. In that case you are just checking the first shipment and status code of it.

I've attached an image with an example on how this could work:

Let me know if this helps!