Orchestration
...
Native Actions
Using the Loop Native Action
17 min
the loop native action in swimlane turbine enables orchestrators to apply one or more actions to each item in an array or object this makes processing collections 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 and objects by iterating through each element this allows users to apply actions systematically, ensuring consistency and efficiency in handling repetitive tasks within workflows loops can iterate over arrays, objects, or strings, and provide access to iteration context (index, key, value) within the loop body 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 or object by using the foreach loop or while loop, you can process items efficiently loops allow you to receive an array, object, or string as input and process each element using a playbook property or expression access iteration context (index, key, value) within loop actions using $loop or $loops expressions aggregate loop action outputs process nested collections by using loops within loops implement action branching where necessary use the output array from a loop in downstream actions exit loops early using the exit loop action accessing loop iteration data within a loop, you can access the current iteration's data using expressions $loop value the current iteration's value (the array element or object value) $loop key the current iteration's key (array index as string, or object property name) $loop index the current iteration's numeric index (0 based) for nested loops, use the $loops prefix with the loop action name $loops loopactionname value access the value from a specific nested loop $loops loopactionname key access the key from a specific nested loop $loops loopactionname index access the index from a specific nested loop example if you have a loop iterating over \['apple', 'banana', 'cherry'] first iteration $loop value = 'apple' , $loop key = '0' , $loop index = 0 second iteration $loop value = 'banana' , $loop key = '1' , $loop index = 1 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, object, or string there are two modes available parallel foreach loops actions are applied to items asynchronously, using inputs from a playbook property or expression the collection is processed in parallel with a default maximum concurrency of 5 (configurable) however, output elements may not maintain their input sequence parallel loops are useful for independent operations that don't require sequential processing sequential foreach loops process items in sequence, one after the other, using inputs from a playbook property or expression the output array maintains the input sequence sequential loops are useful when order matters or when operations depend on previous iterations 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 evaluates to false while loops support condition a boolean expression that determines whether the loop continues limit maximum number of iterations (default 5000, configurable) duration maximum execution time in milliseconds delay delay between iterations in milliseconds (applied after the first iteration) 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 in order output maintains input sequence parallel process items asynchronously output may not maintain input sequence default maximum concurrency is 5 iterations at a time in the configuration section click select property or expression to define the array, object, or string the loop will iterate over the loop can iterate over arrays each element becomes $loop value , with $loop key as the index string objects each property value becomes $loop value , with $loop key as the property name strings each character becomes $loop value , with $loop key as the index string add actions or connectors inside the loop to apply operations to each element use $loop value , $loop key , or $loop index in expressions to reference the current iteration's data 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 the loop continues while the condition evaluates to true configure loop limits (optional but recommended) limit set the maximum number of iterations (default 5000) the loop will fail if this limit is exceeded duration set the maximum execution time in milliseconds the loop will fail if this duration is exceeded delay set the delay between iterations in milliseconds this delay is applied after the first iteration add actions or connectors inside the loop to execute for each iteration ensure actions within the loop modify variables or conditions that will eventually cause the condition to evaluate to false test the playbook to ensure the loop exits correctly to prevent infinite loops important while loops will automatically exit if the condition evaluates to false the iteration limit is reached (default 5000) the duration limit is exceeded (if configured) an exit loop action is encountered 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 exit loop action the exit loop action allows you to exit a loop early before all iterations are complete when an exit loop action is encountered the current iteration completes normally remaining iterations are skipped the loop action completes successfully downstream actions after the loop continue execution use cases exit when a specific condition is met (e g , found the target item) exit on error conditions exit when a threshold is reached note exit loop only exits the innermost loop that contains it in nested loops, you may need multiple exit loop actions to exit outer loops best practices define clear exit conditions for while loops, ensure the condition will eventually evaluate to false to avoid infinite loops use limit and duration settings as safeguards use appropriate loop types use sequential loops when order matters or operations depend on previous iterations use parallel loops for independent operations that can run concurrently set while loop limits always configure a limit and/or duration for while loops to prevent infinite execution the default limit is 5000 iterations use descriptive variable names use clear names for loop conditions and inputs to improve readability minimize actions inside loops keep the number of actions inside loops to a minimum to optimize performance, especially for parallel loops access loop data correctly use $loop value , $loop key , and $loop index to access iteration data for nested loops, use $loops loopname value handle loop outputs be aware that parallel loops may not maintain input sequence in outputs use sequential loops if order is critical test with sample data test loops with various data sizes and edge cases (empty arrays, single items, large arrays) to validate behavior monitor loop execution use logging or debugging actions to monitor loop iterations and identify performance issues consider performance for large arrays, consider using parallel loops for better performance, but be aware of concurrency limits (default 5) 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 select foreach and parallel mode for concurrent processing configure the loop to iterate over $event data ipaddresses (or your array property) within the loop, add an http request action to perform a geolocation lookup using $loop value as the ip address access results using $actions loopactionname result in downstream actions aggregate the results to display or use in downstream actions note since this uses parallel processing, the results may not be in the same order as the input array 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 (e g , $event data users ) within the outer loop, add another loop action to iterate over roles (e g , $loop value roles ) access data from both loops current user $loops outerloopname value current role $loop value user name $loops outerloopname value name perform actions such as logging or applying permissions to each role use variables to aggregate results if needed note you can nest up to 5 loops use descriptive loop names to make $loops references clear 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 is not "completed" (e g , $variables taskstatus != 'completed' ) configure loop limits set limit to 100 iterations (or appropriate value) set duration to 5 minutes (300000 ms) to prevent infinite execution set delay to 5 seconds (5000 ms) between status checks inside the loop, add an action to query the status of tasks and update the $variables taskstatus variable the loop will exit when the condition evaluates to false (status becomes "completed") the iteration limit is reached the duration limit is exceeded important always set limits and duration for while loops to prevent infinite execution example 4 processing paginated api responses scenario retrieve all pages of an api response and process each item create a variable to store the next page token (e g , nextpagetoken ) add a while loop action to the playbook set the condition to continue looping while the next page token exists (e g , $variables nextpagetoken != null && $variables nextpagetoken != '' ) configure loop limits set limit to prevent excessive api calls (e g , 50 pages) set duration to prevent long running loops set delay if the api has rate limits inside the loop add an http request action to fetch the current page using $variables nextpagetoken process the items from the response update $variables nextpagetoken with the next page token from the response the loop exits when there are no more pages or limits are reached alternative approach use a foreach loop with a nested while loop to process items within each page troubleshooting infinite loops while loops can run indefinitely if the condition never evaluates to false always set a limit (default 5000 iterations) set a duration limit ensure actions within the loop modify variables that affect the condition test with sample data to verify exit conditions loop fails with "maximum iteration limit exceeded" the while loop has reached its maximum iterations (default 5000) either increase the limit if appropriate fix the condition so it exits earlier review the logic to ensure the condition can become false loop fails with "duration exceeded" the while loop has exceeded its duration limit review the delay settings and loop logic parallel loop output order parallel loops may not maintain input sequence use sequential loops if order matters, or sort the output if needed loop variables not accessible ensure you're using the correct syntax current loop $loop value , $loop key , $loop index nested loops $loops loopactionname value variable names are case sensitive performance issues too many actions inside loops can slow execution parallel loops have a concurrency limit (default 5), so very large arrays may take time consider breaking large loops into smaller batches exit loop not working ensure the exit loop action is inside the loop you want to exit exit loop only exits the innermost containing loop empty array/object loops over empty collections will complete immediately without executing loop body actions common pitfalls infinite loops caused by missing or improper exit conditions in while loops performance bottlenecks with too many actions in parallel loops incorrect configurations of input arrays, objects, or conditions order dependency issues when using parallel loops where sequence matters nested loop confusion when accessing variables from multiple loop levels missing loop limits in while loops leading to excessive execution time additional resources click for an example of using loops to automate remediation actions