Loop over an array using Group Node


In a blank pre-existing workflow add a new search node. Click the plus icon in the top right of the Cargo Editor and pick a relevant search node. In this example, we will use the Sales navigator search node.

Use node's input configuration to define all relevant filters. Review the limit setting in order to control the size of your array.


Run the search node that we added in the previous step with the right filters to output an array of companies. In order to do so, click the execute node button in the top right of the node configuration side panel.

Wait while the API call is running in the background. Once results are ready you can inspect the returned data in the side panel.

Encountered an error? Troubleshoot your workflow using our Error Handling reference


Add a group node to your workflow from the node catalog. Position it below the previous node and link them together.


Now we need to configure the newly added group node by specifying the items parameter. This way we select which array we want this group node to loop over. You can use the variables dropdown by clicking the items text field or paste the expression value:

Pass the array of leads to the group node

{{nodes.salesNavigator_search}}

Click on the expand button on the bottom-right of the group node to enter the child workflow that will handle each element. This child workflow can include any combination of nodes that you need to process the array elements.

For example, you can add nodes to send an email, log data, or perform transformations on each element of the array. In our case, we will enrich company details for each lead retrieved earlier.

Hint: to exit the child workflow click done in the top right corner of the editor.


Now let's add a node inside the sub-workflow. Click the "add node" button and drag "sales navigator enrich" node onto the canvas. Link the new node and configure it by selecting "start" in the expression builder.

The start node of the child workflow will be executed with each list item individually. That's how we can run the enrich operation multiple times for each lead obtained in the main workflow.


Good to know: if you need to access any element in the parent workflow, you can use the parentNode object from within the child workflow.

Reference the hubspot_owner_id of the company available in the parent workflow

{{ parentNodes.start.hubspot_owner_id }}

With the sub-workflow configured, go back to the main workflow by clicking the "done" button in the top right. Now execute the group node by clicking the "play" button in the right-side panel.

The output will contain a preview for just the first item of the group node list, but after publishing this workflow will run it for each entry without such limit.


Outcome

Finish line

By now, you have successfully passed an array to a group node and processed each element inside a child workflow.

Once the group node has finished successfully executing, it will output an array containing the output of the last node in the 'child workflow' for all the executions. This array can be used in the parent workflow to further process the data or be sent to another group node.

For instance, if you had chosen to enrich each of the domains passed by the sales navigator node for the relevant stakeholders, you could output an array of these stakeholders from the first group node and process this array inside a second group node.

What's next?