Orchestration
...
Native Actions
Using Variables in Playbooks
13 min
the variables feature in swimlane turbine allows orchestrators to collect, store, and use data across various actions within playbooks by leveraging the create variables and update variables native actions, orchestrators can define and modify variables without writing any code this enables greater flexibility and ease of use in complex workflows overview variables in swimlane turbine serve as temporary data storage that can be dynamically manipulated throughout the execution of a playbook this allows playbooks to make decisions, manage data, and pass information between actions seamlessly key benefits dynamic data handling easily collect, modify, and utilize data throughout the workflow code free configuration create and update variables without the need for scripting improved flexibility enable complex logic and decision making capabilities by dynamically adjusting the flow of actions seamless integration variables can be used across different actions, ensuring smooth data flow and continuity within playbooks promotable variables promote variables for accessibility across multiple playbooks, enhancing reusability and reducing redundancy creating variables the create variables native action enables orchestrators to generate new variables that can be applied across downstream actions important you cannot create a variable that already exists if you attempt to create a variable with a name that already exists, the action will fail use the update variables action to modify existing variables instead here's how to use it start by adding a trigger or existing playbook action to ensure upstream data is available for the variables from the add panel, drag and drop the create variables action onto the playbook canvas click configure , then select add variable a list of available property types will appear the following types are currently supported string, number, boolean, object, array, or attachment if you want to add more than one variable, click add variable again and select another property type in the variable box, enter a value directly or click select a property to open the property drawer the property drawer displays all available inputs from upstream playbooks, actions, or event inputs you can also select expression and use dot notation for advanced variable manipulation variables can be accessed in expressions using the $variables prefix (e g , $variables myvariable ) if you want the variable accessible outside of the current playbook, click +promote promoted variables can be accessed in other playbooks through the playbook's published outputs using the $published variables prefix followed by the variable name you can mark the data as sensitive while creating a variable click the ellipsis button next to the select a property and click mark sensitive now that the variable is created, you can reference it in subsequent actions in the next action's configuration, under inputs , click select a property to access the variable from the playbook property drawer congratulations! you now have a variable to use in your playbook workflow example creating an object variable here’s an example of creating an object variable to store a url drag and drop the create variables action add a new variable, select object as the type, and name it object test2 under object test2 , add a property named string akbds and set its value to $event data url promote the variable if you want to use it across multiple playbooks updating variables if you need to modify an existing variable, use the update variables action the update variables action supports multiple operation types to modify variables in different ways note if a variable doesn't exist when updating, it will be created automatically using the operation's value (effectively behaving like a set operation) below is an example where a string and object variable are updated how to update variables add the update variables action to the playbook canvas, then click configure click select variable to update to open the playbook property drawer from here, select the variable you want to modify once selected, choose an update operation type and enter new data, choose a playbook property, or use an expression to update the variable the variable is now updated and can be used in subsequent actions update operation types the update variables action supports four operation types set replaces the variable's value with a new value this is the default operation type and works with any variable type merge merges objects together or concatenates arrays for objects, properties from the new value are merged into the existing object for arrays, the new array is concatenated to the existing array this operation only works with object or array variable types append appends a value to an array variable the value is added to the end of the existing array the value to append should be an array or array like structure that will be concatenated to the existing array this operation only works with array variable types arithmetic performs arithmetic operations on number variables supported operators include add adds the specified value to the variable subtract subtracts the specified value from the variable multiply multiplies the variable by the specified value divide divides the variable by the specified value this operation only works with number variable types example updating a string variable here's an example of updating a string variable select the string variable string 1 choose the set operation type set its new value to "good job" apply the changes and continue building your playbook accessing variables variables created in a playbook are accessible to all downstream actions in the same execution path you can reference variables in expressions using the $variables prefix followed by the variable name for example $variables mystringvariable accesses a string variable $variables myobjectvariable propertyname accesses a property within an object variable $variables myarrayvariable\[0] accesses an element in an array variable variables are scoped to the execution path, meaning variables created on separate branches of conditional logic are not accessible to actions on other branches advanced use cases handling arrays use arrays to store lists of values and iterate over them with loop actions create an array variable named email list using the create variables action add email addresses as elements within the array use the update variables action with the append operation to add more items to the array use a loop action to iterate through each email and perform actions like sending notifications or logging details performing arithmetic operations use the update variables action with arithmetic operations to perform calculations create a number variable named counter and set its initial value use update variables with the arithmetic operation to increment, decrement, multiply, or divide the counter reference the updated counter value in subsequent actions merging objects use the merge operation to combine object properties create an object variable with initial properties use update variables with the merge operation to add or update properties from another object the merge operation combines properties, with new values overwriting existing ones for matching keys error handling with variables use variables to capture and log error messages dynamically create a string variable named error message in your error handling action, use update variables to set the variable to the error output using an expression or property selection log or display the variable in subsequent actions to track errors efficiently troubleshooting variable creation fails if you receive an error that a variable already exists, use the update variables action instead of create variables to modify the existing variable variable not updating ensure the variable is correctly referenced and updated in the action check for spelling errors or incorrect property paths verify that you're using the correct operation type for the variable's data type (e g , append only works with arrays, arithmetic only works with numbers) merge operation fails the merge operation only works with object or array variable types ensure both the variable and the input value are objects or arrays arithmetic operation fails the arithmetic operation only works with number variable types ensure the variable contains a valid number value append operation fails the append operation only works with array variable types ensure the variable is an array unexpected variable values review upstream actions to ensure data is being passed correctly use logs or debugging actions to trace variable changes remember that variables are scoped to execution paths, so variables from separate branches may not be accessible missing variables in property drawer confirm that variables are promoted if needed for accessibility in other playbooks variables must be created upstream in the execution path to be accessible to downstream actions best practices keep variables organized use descriptive names and add clear descriptions to your variables to make your playbooks easier to understand choose the right action use create variables for new variables and update variables for modifying existing ones remember that create variables will fail if the variable already exists select appropriate operations choose the correct update operation type for your use case use set for simple value replacement use merge for combining objects or arrays use append for adding items to arrays use arithmetic for numeric calculations understand variable scoping variables are scoped to execution paths variables created on one branch of conditional logic are not accessible to actions on other branches promote when necessary only promote variables that need to be accessible across multiple playbooks to avoid cluttering the global variable space test variable logic regularly test your playbooks to ensure variables are set and updated correctly, especially when using different operation types use expressions wisely leverage expressions with the $variables prefix for complex variable logic, but keep them as simple as possible for maintainability