# JavaScript: Run Code

Executes custom JavaScript in Google's V8 engine to transform data, apply conditional logic, or run calculations mid-workflow.


> **Availability:** See the [Incident Workflow Actions Overview table](/workflow-actions) for the plans this workflow is available on.

## 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, follow the instructions to [Create an Incident Workflow](/ai-automation/automation/incident-workflows#create-an-incident-workflow).
2. When the instructions prompt you to [add actions](/ai-automation/automation/incident-workflows#add-actions), select **this action**.
3. Enter the following **Inputs** and click **Save**.
4. Continue following instructions to **Publish** the Workflow.
5. When the action runs, you will see the **Outputs** listed below.

## Inputs

> **Field References:** Fields with the **\{+\}** icon accept [Field References](/ai-automation/automation/incident-workflows#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](/ai-automation/automation/incident-workflows#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](/ai-automation/automation/incident-workflows#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](/ai-automation/automation/incident-workflows#field-references) (e.g., `workflow.id`) as part of your JavaScript code.

```javascript
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.

```javascript
var requestBodyForHttpAction = {
incidentID: incident.id,
currentDateTime: new Date().toISOString()
};

setOutput(JSON.stringify(requestBodyForHttpAction));
```
