Skip to main content

For Each Loop

A For Each Loop runs actions once for every item of a group, such as one export per order line or one email per shipment.

The loop​

Add action adds a For Each Loop like any action. It has no name, number or switch of its own: the actions inside it have theirs.

  • Data: Data chooses what the loop reads: the Extraction data, or the output of a data transformation above it.
  • Group: Group chooses the list in that data the loop walks, such as annotations.shipments. A loop walks one list; a list inside a list needs a data transformation first.

Actions in a loop​

Add action inside the loop adds any action except another loop. Each runs once per item.

  • Loop item: An export in a loop sends the Loop item by default, the item as JSON. An FTP export adds the item's position to the file name, unless the name already uses a value of the item.
  • Values of the item: In an email, Insert field and To offer the values of the item, written as item followed by the path, such as item.shipment_number.value.
  • Data transformation: A data transformation in a loop reads the loop's data with the item added as data.item. The actions after it in the loop can send or attach its output for that item.
  • Create PDF: A Create PDF in a loop makes one PDF per item. The emails and FTP exports after it in the loop can send the PDF of that item.

Actions outside the loop cannot use what an action inside the loop made, because that exists once per item.

When a loop runs​

A loop takes its turn in the list from top to bottom. Nothing is sent until every item is ready: a problem with one item stops the export before anything goes out.

A group without items is not an error: the loop does nothing and the actions after it run. A loop takes up to 200 items. A loop over the extraction data is counted before any action runs, so a group that is too large stops the export before the actions above the loop send anything.

When an item fails​

The first item that fails stops the export. The upload stays in the Inbox with "Export failed", and a comment on the task names the item and the action, such as "Item 4 of 10, Email the shipper".

Retry export continues at that item. Items that were sent are not sent again, also after you unlock the task, change it and complete it again: an item goes out a second time only when what is sent has changed.

Delete a loop​

Delete loop removes an empty loop. Delete the actions inside it first.