Skip to main content

    Automation Utils

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

    npm install @dynatrace-sdk/automation-utils

    Functions

    actionExecution

    actionExecution(id?): Promise<ActionExecution>

    Retrieves the action execution details for the current workflow.

    Parameters

    NameTypeDescription
    idstringThe 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.

    Code example

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

    Code example

    //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;

    execution

    execution(id?): Promise<IExecution>

    Retrieves the execution details for the current workflow.

    Parameters

    NameTypeDescription
    idstringThe ID of the execution to retrieve. If not provided, the ID from the caller service metadata is used.

    Returns

    Description
    The execution details.

    Code example

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

    const exe = await execution();

    Code example

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

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

    Code example

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

    const exe = await execution();
    const result = await exe.result();
    getExecutionLink(): null | string

    Returns

    Description
    The link to a workflow execution, or null if called within a simple workflow or outside a workflow.
    getTaskExecutionLink(): null | string

    Returns

    Description
    The link to a workflow execution, including the currently executed task name, or null if called within a simple workflow or outside a workflow.
    getWorkflowLink(): null | string

    Returns

    Description
    The link to a workflow, or null if called outside a workflow.

    result

    result(predecessorTaskName): Promise<any>

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

    Parameters

    NameTypeDescription
    predecessorTaskName*requiredstringThe name of the predecessor task.

    Returns

    Description
    The result of the predecessor task execution.

    Code example

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

    const taskExecutionResult = await result('predecessor_task_1');

    Constants

    actionExecutionId

    ID of the running action execution.

    executionId

    ID of the running execution.

    taskName

    Name of the running task.

    workflowId

    ID of the running workflow.

    Types

    IExecution

    Extended execution type. Adds helper methods to the base Execution:

    Properties

    NameTypeDescription
    actor*requiredstring
    endedAtnull | Date
    eventTriggernull | string
    id*requiredstring
    inputExecutionInput
    isDraftboolean
    paramsExecutionParams
    parentExecution*requirednull | string
    parentTaskName*requirednull | stringParent task execution's name (subworkflows only)
    providedInputnull | ExecutionProvidedInput
    rootExecutionnull | string
    rootWorkflownull | string
    runtime*requirednumber

    Calculate the runtime of an execution in seconds. If the execution is not ended, runtime is calculated until now.

    schedulenull | string
    startedAtDate
    state*required"ERROR" | "RUNNING" | "SUCCESS" | "UNKNOWN" | "PAUSED" | "CANCELLED"
    stateInfonull | string
    title*requiredstring
    triggernull | string
    triggerType*required"Manual" | "Schedule" | "Event" | "Workflow"
    triggerTypeDetailTriggerTypeDetail
    usernull | string
    workflow*requiredstringExecuted Workflow
    workflowType*required"STANDARD" | "SIMPLE"
    workflowVersion*requirednull | number

    Methods

    event
    event(): null | Record<string | string>

    Returns the event context payload associated with the execution.

    Returns

    Description
    A key-value object if event data is available, otherwise null.

    Code example

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

    const exe = await execution();
    const eventContext = exe.event();
    result
    result(taskId): Promise<any>

    Retrieves the result of a task execution.

    Parameters

    NameTypeDescription
    taskId*requiredstringThe ID of the task whose result should be retrieved.

    Returns

    Description
    A promise resolving with the task execution result.

    Code example

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

    const exe = await execution();
    const result = await exe.result("task-id");
    Still have questions?
    Find answers in the Dynatrace Community