---
title: "Automation Utils"
description: Utility functions for accessing AutomationEngine APIs from the Run JavaScript action.
---


# Automation Utils

Utility functions for accessing AutomationEngine APIs from the Run JavaScript action.

import NpmLogo from '@site/static/img/npm-logo.png';

<div class="row margin-bottom--md">
  <div class="col">
    <a href="https://www.npmjs.com/package/@dynatrace-sdk/automation-utils" target="_blank" rel="noopener noreferrer"> <span class="margin-right--xs">@dynatrace-sdk/automation-utils</span> <img className="no-zoom" width="20px" src={NpmLogo} /> </a>
  </div>
  <div class="col" style={{textAlign: 'right'}}>
    <a href="https://www.npmjs.com/package/@dynatrace-sdk/automation-utils/v/2.5.1" target="_blank" rel="noopener noreferrer">v2.5.1</a>
  </div>
</div>

```bash
npm install @dynatrace-sdk/automation-utils
```


## Functions



### actionExecution

<div class="padding-bottom--md">
<strong>actionExecution(id?): Promise&lt;ActionExecution&gt;</strong>

<div class="padding-left--md">

**Required scope:** automation:workflows:read

Retrieves the action execution details for the current workflow.
Available for executions of workflows type standard only (simple workflow executions will result in 404)



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|id|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The ID of the action execution to retrieve. If not provided, the ID from the caller service metadata is used. |




#### Returns

| Description |
|---|
|The action execution details.|



<details>
<summary>
Code example
</summary>

```ts
// To get current action execution detail
import { actionExecution } from '@dynatrace-sdk/automation-utils';
const actionExe = await actionExecution();
```

</details>

<details>
<summary>
Code example
</summary>

```ts
// To get loopItem from current action execution
import { actionExecution } from '@dynatrace-sdk/automation-utils';

const actionExe = await actionExecution();
const loopItem = actionExe.loopItem;
// or
const { loopItem } = actionExe;
```

</details>



</div>





### execution

<div class="padding-bottom--md">
<strong>execution(id?): Promise&lt;[IExecution](#iexecution)&gt;</strong>

<div class="padding-left--md">

**Required scope:** automation:workflows:read

Retrieves the execution details for the current workflow.
Available for executions of workflows type standard only (simple workflow executions will result in 404)



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|id|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The ID of the execution to retrieve. If not provided, the ID from the caller service metadata is used. |




#### Returns

| Description |
|---|
|The execution details.|



<details>
<summary>
Code example
</summary>

```ts
// To get current execution detail
import { execution } from '@dynatrace-sdk/automation-utils';

const exe = await execution();
```

</details>

<details>
<summary>
Code example
</summary>

```ts
// To get event context from current execution
import { execution } from '@dynatrace-sdk/automation-utils';

const exe = await execution();
const eventContext = exe.event();
```

</details>

<details>
<summary>
Code example
</summary>

```ts
// To get current task execution result
import { execution } from '@dynatrace-sdk/automation-utils';

const exe = await execution();
const result = await exe.result();
```

</details>



</div>





### getExecutionLink

<div class="padding-bottom--md">
<strong>getExecutionLink(): null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)</strong>

<div class="padding-left--md">





</div>



#### Returns

| Description |
|---|
|The link to a workflow execution, or <code>null</code> if called within a simple workflow or outside a workflow.|





</div>





### getTaskExecutionLink

<div class="padding-bottom--md">
<strong>getTaskExecutionLink(): null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)</strong>

<div class="padding-left--md">





</div>



#### Returns

| Description |
|---|
|The link to a workflow execution, including the currently executed task name, or <code>null</code> if called within a simple workflow or outside a workflow.|





</div>





### getWorkflowLink

<div class="padding-bottom--md">
<strong>getWorkflowLink(): null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)</strong>

<div class="padding-left--md">





</div>



#### Returns

| Description |
|---|
|The link to a workflow, or <code>null</code> if called outside a workflow.|





</div>





### result

<div class="padding-bottom--md">
<strong>result(predecessorTaskName): Promise&lt;[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)&gt;</strong>

<div class="padding-left--md">

**Required scope:** automation:workflows:read

Retrieves the result of a task execution in the current workflow.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|predecessorTaskName<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the predecessor task. |




#### Returns

| Description |
|---|
|The result of the predecessor task execution.|



<details>
<summary>
Code example
</summary>

```ts
//To get a predecessor task execution's result
import { result } from '@dynatrace-sdk/automation-utils';

const taskExecutionResult = await result('predecessor_task_1');
```

</details>



</div>



## Constants

### actionExecutionId
<div class="padding-left--md">

ID of the running action execution.

</div>

<div class="padding-left--md">
[string](https://developer.mozilla.org/en-US/docs/Glossary/String)

</div>

### executionId
<div class="padding-left--md">

ID of the running execution.

</div>

<div class="padding-left--md">
[string](https://developer.mozilla.org/en-US/docs/Glossary/String)

</div>

### taskName
<div class="padding-left--md">

Name of the running task.

</div>

<div class="padding-left--md">
[string](https://developer.mozilla.org/en-US/docs/Glossary/String)

</div>

### workflowId
<div class="padding-left--md">

ID of the running workflow.

</div>

<div class="padding-left--md">
[string](https://developer.mozilla.org/en-US/docs/Glossary/String)

</div>

## Types

### IExecution
Extended execution type.
Adds helper methods to the base [Execution](#execution):
 - [IExecution.result](#iexecution.result)—retrieve the result of a task execution.
 - [IExecution.event](#iexecution.event)—get the event payload context of the execution.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|actor<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|endedAt|null &#124; Date| |
|eventTrigger|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|id<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|input|ExecutionInput| |
|isDraft|[boolean](https://developer.mozilla.org/en-US/docs/Glossary/Boolean)| |
|params|ExecutionParams| |
|parentExecution<sup>*required</sup>|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|parentTaskName<sup>*required</sup>|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)|Parent task execution's name (subworkflows only) |
|providedInput|null &#124; ExecutionProvidedInput| |
|rootExecution|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|rootWorkflow|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|runtime<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)|<p>Calculate the runtime of an execution in seconds. If the execution is not ended, runtime is calculated until now.</p>  |
|schedule|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|startedAt|Date| |
|state<sup>*required</sup>|"ERROR" &#124; "RUNNING" &#124; "SUCCESS" &#124; "UNKNOWN" &#124; "PAUSED" &#124; "CANCELLED"| |
|stateInfo|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|title<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|trigger|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|triggerType<sup>*required</sup>|"Manual" &#124; "Schedule" &#124; "Event" &#124; "Workflow"| |
|triggerTypeDetail|TriggerTypeDetail| |
|user|null &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)| |
|workflow<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|Executed Workflow |
|workflowType<sup>*required</sup>|"STANDARD" &#124; "SIMPLE"| |
|workflowVersion<sup>*required</sup>|null &#124; [number](https://developer.mozilla.org/en-US/docs/Glossary/Number)| |

#### Methods



##### event

<div class="padding-bottom--md">
<strong>event(): null &#124; Record&lt;[string](https://developer.mozilla.org/en-US/docs/Glossary/String) &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)&gt;</strong>

<div class="padding-left--md">

**Required scope:** automation:workflows:read

Returns the event context payload associated with the execution.



</div>



#### Returns

| Description |
|---|
|A key-value object if event data is available, otherwise <code>null</code>.|



<details>
<summary>
Code example
</summary>

```ts
import { execution } from '@dynatrace-sdk/automation-utils';

const exe = await execution();
const eventContext = exe.event();
```

</details>



</div>





##### result

<div class="padding-bottom--md">
<strong>result(taskId): Promise&lt;[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)&gt;</strong>

<div class="padding-left--md">

**Required scope:** automation:workflows:read

Retrieves the result of a task execution.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|taskId<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The ID of the task whose result should be retrieved. |




#### Returns

| Description |
|---|
|A promise resolving with the task execution result.|



<details>
<summary>
Code example
</summary>

```ts
import { execution } from '@dynatrace-sdk/automation-utils';

const exe = await execution();
const result = await exe.result("task-id");
```

</details>



</div>




