The For-Each function is used in performing multiple actions from a single workflow.
For example, if you want to add all employees from the HRMS tool to the Access Management tool. Here, For-Each function can be helpful in capturing individual employee details from the HRMS tool using Get all employees action and then add each employee details in the Access Management tool.
Let us see how you can do the same using the For-Each function:
1. After you have created a Workflow with trigger, click the plus icon and select Add Action.
2. Select the desired Application from the drop-down menu (here BambooHR).
3. Select the Action as Get all Employees
4. Enter the account details and click Connect Account.
5. When you’re done, click Save.
6. Click on Requester Email input field and select Supervisor Email as Requester Email from the Variable Picker.
7. Click Save.
8. Click on the plus icon below the Get All Employees block and select Add For Each.
9. Enter a relevant name for this function in the For-Each Name field
10. Select the output from BambooHR (Employee Details) in the Select a Collection Box field.
11. Enter a relevant summary of the added conditions in the For-Each Summary field.
12. When you’re done, click Save.
13. Click on the plus icon inside the For-Each block and select Add Action.
14. Select the desired Application (here Microsoft Azure AD)
15. Select the Action as Add User.
16. Enter the relevant connection details and click Connect Account to connect to your Microsoft Azure AD account.
17. Update the Input by clicking the right arrow (>) in the Variable Picker.
NOTE: The input field can only be the output data selected from the For-Each function.
Upon clicking on the right arrow (>) from the Variable Picker, all the input fields are revealed.
18. Map appropriate fields in the Input fields using the Variable Picker box
19. Once all the Input fields are mapped, click on Enable Error Handling to handle the Success & Failure scenarios for the automation.
The Error Handling features allows the chatbot to proceed with the automation even if the Action fails.
20. Once the For-Each function is completed, you can continue with the workflow by adding more actions to the workflow, if desired.
21. Once you have set up the workflow, you can test the workflow by clicking on the Test button on the top right corner of the screen and the trigger workflow will start the execution.