Orchestration
...
Native Actions
Using the Loop Native Action
20 min
the loop native action in swimlane turbine enables orchestrators to apply one or more actions to each item in an array this makes processing arrays more efficient by iterating over each element and applying the necessary actions loops provide orchestrators with flexibility while maintaining clarity and control overview the loop action provides a streamlined way to process arrays by iterating through each element this allows users to apply actions systematically, ensuring consistency and efficiency in handling repetitive tasks within workflows key benefits of the loop action native action easily accessible within the playbook builder efficient array processing simplifies operations on arrays by automating repetitive tasks flexible integration works seamlessly with other actions and connectors in the playbook supports nested arrays capable of handling complex data structures through nested loops parallel and sequential processing offers asynchronous and synchronous processing options for foreach loops to suit different workflow requirements conditional iteration allows for conditional processing using while loops using the loop action as an orchestrator, you may need to apply one or more actions to each item in an array by using the foreach loop or while loop, you can process items efficiently loops allow you to receive an array as input and process each element using a playbook property or expression aggregate loop action outputs process nested arrays (arrays within arrays) by using loops within loops implement action branching where necessary use the output array from a loop in downstream actions a maximum of five nested loops is allowed within a single playbook adding loops to a flow open your playbook in the turbine canvas from the list of native actions on the left hand panel, locate loop action drag and drop the loop action into your flow once added, the loop will appear as part of the flow, waiting for configuration providing a title and description for the loop adding a title when you select the loop action in your flow, the configuration panel will open locate the title field at the top of the panel enter a descriptive title that reflects the purpose of the loop (for example, process user records or iterate over ip addresses) adding a description below the title field, you will find the description field use this field to provide additional details about the loop's purpose and function (for example, this loop processes each user record to validate login attempts) click the contains sensitive data checkbox if you have any sensitive data tip use meaningful and concise titles and descriptions to improve the readability and maintainability of your playbooks types of loops there are two types of loops foreach loops these loops iterate over each item in an array there are two modes available parallel foreach loops actions are applied to items in an array asynchronously, using array inputs from a playbook property or expression the array is processed in parallel with a maximum concurrency of 10 however, output elements may not maintain their input sequence sequential foreach loops process items in sequence, one after the other, using array inputs from a playbook property or expression the output array maintains the input sequence while loops these loops iterate based on a condition and process items sequentially a condition must be configured, and the loop continues until the condition is met configuring loops configuring foreach loops click on the loop action to open its configuration panel select foreach under the type of loop choose the process type sequential process items one by one parallel process items asynchronously in the configuration section click select property or expression to define the array or list the loop will iterate over add actions or connectors inside the loop to apply operations to each array element configuring while loops click on the loop action to open its configuration panel select while under the type of loop click edit condition to define the loop condition using expressions, properties, or variables add actions or connectors inside the loop to execute for each iteration test the playbook to ensure the loop exits correctly to prevent infinite loops configuring the loop after setting the condition once the loop condition is set, click the configure button in the configuration section use the configuration panel to refine inputs specify additional properties or expressions required by the loop outputs define how the loop outputs should be used in downstream actions test the playbook to validate the loop's behavior and ensure configurations are correct best practices define clear exit conditions for while loops to avoid infinite loops use descriptive variable names for conditions or loop inputs minimize actions inside a loop to optimize performance test loops with sample data to validate their behavior log or debug loop iterations to monitor execution configuring actions inside the loop inside the loop, drag and drop the next connector/action to the plus icon to add it to the flow in the automated remediation playbook, a script native action is used to filter top traffic sites when the loop action is triggered, the foreach loop iterates over the specified items you can nest up to five loops inside one another deleting a loop will remove the entire loop, including all nested actions, connectors, and sub loops you have successfully added and configured a loop for more information on downstream outcomes after configuring loops, refer to the automated remediation playbook advanced examples example 1 processing a list of ip addresses scenario use the loop action to apply a geolocation lookup to each ip address in an array add a loop action to iterate over the array of ip addresses within the loop, add a connector to perform a geolocation lookup aggregate the results to display or use in downstream actions example 2 nested loops for complex data structures scenario process nested arrays (e g , list of user data, where each user has multiple roles) add an outer loop to iterate over users within the outer loop, add another loop action to iterate over roles perform actions such as logging or applying permissions to each role example 3 using a while loop for conditional processing scenario monitor a task queue until all tasks are marked as "completed " add a while loop action to the playbook set the condition to check if the "task status" property is not equal to "completed " inside the loop, add an action to query the status of tasks optionally, include a delay or pause action to avoid excessive looping example 4 processing paginated api responses scenario retrieve all pages of an api response and process each item add a while loop action to the playbook set the condition to continue looping while the "next page" property is not empty inside the loop, add an action to fetch the current page of data process the items and update the "next page" property for subsequent iterations common pitfalls infinite loops caused by missing or improper exit conditions performance bottlenecks with too many actions in parallel loops incorrect configurations of input arrays or conditions additional resources click automated remediation use case docid\ ocn77daazwyirurddioxa for an example of using loops to automate remediation actions