Workflow Actions
JavaScript: Run Code
Executes custom JavaScript in Google's V8 engine to transform data, apply conditional logic, or run calculations mid-workflow.
Availability
Description
Execute JavaScript code to process data, use conditional logic, perform advanced calculations, and more.
JavaScript Engine
Instructions
- If you have not done so, follow the instructions to Create an Incident Workflow.
- When the instructions prompt you to add actions, select this action.
- Enter the following Inputs and click Save.
- Continue following instructions to Publish the Workflow.
- When the action runs, you will see the Outputs listed below.
Inputs
Field References
Fields with the {+} icon accept Field References, which can be useful for referencing incident data or outputs created in prior workflow steps. To add Field References, click {+}, or enter {{, and select relevant fields. Refer to the Field References article for more information.
| Name | Description |
|---|---|
| Code | Enter the JavaScript to run. Set the action’s Output field with setOutput(). setOutput() must be called with a string value. Please read Action-Specific Field References for more information about how to retrieve a value from another workflow action. |
Outputs
| Name | Description |
|---|---|
| Output | The string value passed to setOutput() in the JavaScript Code. |
| Result | Value that shows if the action was successful or not. Either "Success" or "Failed." |
| Result Summary | Brief description of what the action did or if it failed. |
| Error | Brief description that is populated if the action failed. |
Action Limitations
- The maximum output size is 5MB.
- Output must be a string type.
- The execution time limit is 10 seconds.
- The memory limit is 512MB
- Code executes using UTC as the local timezone.
Examples
Reference Workflow Fields
Use Field References (e.g., workflow.id) as part of your JavaScript code.
var workflowId = workflow.id;
setOutput("This Action is part of Workflow: " + workflowId);
Output a Stringified Object
Outputting a stringified object is helpful when constructing a JSON body for an HTTP request.
var requestBodyForHttpAction = {
incidentID: incident.id,
currentDateTime: new Date().toISOString()
};
setOutput(JSON.stringify(requestBodyForHttpAction));