JavaScript: Run Code

📘

Availability

This workflow action is available on our Business and Enterprise for Incident Management pricing plans. Please contact our Sales Team to upgrade to an account with this action.

Description

Execute JavaScript code to process data, use conditional logic, perform advanced calculations, and more.

📘

JavaScript Engine

The code you enter is executed using Google’s V8 JavaScript engine.

Instructions

  1. If you have not done so already, please follow our instructions to Create an Incident Workflow.
  2. When you are prompted to add actions , select this action.
  3. Enter the following Inputs and then click Save. Continue following instructions to Publish the Workflow. When the action runs, you will see the Outputs listed below.

Inputs

NameDescription
CodeEnter 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

NameDescription
OutputThe string value passed to setOutput() in the JavaScript Code.
ResultValue that shows if the action was successful or not. Either "Success" or "Failed."
Result SummaryBrief description of what the action did or if it failed.
ErrorBrief 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));