Process variables allow scripts to exchange data with the process. Scripts can read existing values from process variables, update them, or store the results of calculations and API calls for use by later process steps.
Process variables are exposed through the variables object. Values passed into the script are available as properties of this object, and any values written back to the object become available to subsequent tasks, forms, gateways, and integrations.
The following are common variable operations:
| Operation | Description | Example |
|---|---|---|
| Read an input variable | Reads data passed into the script. Use this when a process, form, connector, or previous task has already populated the variable. |
The following example reads the value of the amount process variable and stores it in a local script variable named amount: const amount = variables.amount; |
| Read an array item | Reads a value from an array variable. Use this when a process variable contains a collection of items, such as documents, users, or order lines. |
The following example reads the first item from the documents process variable and stores it in a local script variable named firstDocument: const firstDocument = variables.documents[0]; |
| Write an output variable | Stores a value that can be used later in the process. Use this when the script calculates or transforms data. |
The following example calculates a total cost by multiplying the cost process variable by 1.2 and stores the result in the totalCost process variable: variables.totalCost = variables.cost * 1.2; |
| Store an API response | Stores data returned by an API call in a process variable for later use. |
The following example retrieves a document using its identifier and stores the returned document object in the document process variable: variables.document = documentApi.getDocumentById(variables.docId, null); |