The Collect operator in Torq is a vital tool for efficiently gathering data from loop iterations into a cohesive array. This functionality simplifies data handling in complex workflows, allowing you to reference results in subsequent steps with ease.
Key Considerations for Using the Collect Operator
Placement: The Collect operator must be used within a loop.
Data Limit: The operator shouldn't be used to collect more than 1MB of data.
Iteration Handling: Each iteration clears the previous results in the array. To maintain all results in a single array, utilize additional Collect operators in the parent loop.
Flatten Results Option
The Flatten Results setting combines all iteration inputs into a single array, simplifying data management for scenarios like paginated results. By default, each iteration's results are stored as separate array items.
Step-by-Step Guide to Using the Collect Operator
Initiate a Loop: Start by adding a Loop operator from the bottom of the Steps Library.
Add the Collect Operator: Hover over the Loop operator to reveal and select the Collect operator. Place it inside the loop.
Configure Collection: In the Collect operator's settings, specify the path to the data you want to gather from each loop iteration, such as
$.ask_a_question.slack_response
for collecting user responses.(Optional) Multiple Collections: To segment the collected data, you can add more Collect operators within the same loop. For instance, to capture only the email addresses of users who declined a request set the path to
$.loop_value
.