Skip to main content

Workflow context

When using actions in event, alert, and incident workflows, you may want to store the result of an action somewhere to be used later on in the same workflow. The workflow context allows you to accomplish this without having to use the event, alert, or incident itself to store data between workflow actions.

Use case example

Suppose that you want to use an incident workflow to extract data from an incident description. You then want to filter the extracted data to decide whether or not the incident should be forwarded to an outbound webhook.

Without the workflow context, you need to extract the data from the description, store it in an incident tag, and reference the tag data in a Filter action to decide whether to forward the incident or not. This approach is not ideal: The data stored in the tag is only relevant to the current workflow and may not be used elsewhere, which clutters the incident fields.

Instead of storing the data you need in a tag, you can create a new workflow context variable and store the data there. You can then reference this data anywhere else you need it in the incident workflow.

Accessing the workflow context from a workflow

You can access the workflow context anytime a workflow action asks you to provide a field. The only exceptions are the Set Tags action and the Add Item to List action, which both do not allow workflow context variables to be used in the output tag field. However, workflow context variables can still be referenced using substitution syntax in the text template fields for these two actions (see the example below).

The following menu will appear whenever the workflow context is available:

workflowContext1.png
  • Click Workflow Context to expand and view the list of workflow context variables that you can read or write to.

  • Click the plus (+) button to create a new workflow context variable to work with. Type the name of the new variable into the space provided. Click the checkmark button once you are done to create the variable. Click the X button to cancel.

  • If you try to create a workflow context variable with a name that already exists, the existing variable will be used instead.

  • The workflow context is local and specific to each workflow.

You can also use workflow context variables inside text fields where substitution syntax is accepted. To reference a workflow context variable in such a field, use the following syntax, where VARIABLE_NAME is the name of your workflow context variable:

${workflowContext.VARIABLE_NAME}
Example 1. Using workflow context variables with substitution syntax inside text fields

Suppose that you have stored the output of a incident workflow action inside a workflow context variable called address. You can reference this variable using substitution syntax in subsequent workflow actions.

For instance, if you have a Set Tags action, you can add the following tag value template:

  • Template: ${workflowContext.address}

  • Output tag: tags.newtag

Or, if you have a Send to Endpoint action, you can specify the following URL for the external link:

https://app.myservice.com/incidents/${workflowContext.address}


Accessing the workflow context from a webhook endpoint

In alert and incident workflows containing a Send to Endpoint action, workflow context variables declared before the webhook endpoint is triggered can be referenced inside the webhook. You can use this to do things like extracting a value from an incoming incident field and using it as part of a webhook endpoint payload, all without having to set a tag.

Workflow context variables can only be used inside the following areas of a webhook endpoint:

  • In both the key and value fields of Headers, located under the Endpoint section.

  • In the Key/Value Editor, located under the Payload Body section.

You can reference workflow context variables in the webhook endpoint by using the following substitution syntax, where VARIABLE_NAME is the name of your workflow context variable:

${workflowContext.VARIABLE_NAME}
Example 2. Using workflow context variables in a webhook endpoint

Suppose that you have created and enabled an incident workflow with the following sequence of actions, with some actions assigning values to workflow context variables that you have declared:

  1. Workflow Trigger

  2. Extract Substring action (assigns a value to workflowContext.accountInfo)

  3. Send to Endpoint action (triggers a webhook endpoint named "My Integration")

  4. Match and Update action (assigns a value to workflowContext.otherInfo)

In your "My Integration" webhook endpoint, you can now create a new header under the Endpoint section with the following key/value pair:

  • Key: account

  • Value: ${workflowContext.accountInfo}

You can also create the following payload body:

{
    "message": "Issue # ${id} with severity ${severity} associated with account ${workflowContext.accountInfo}.",
    "timestamp": "${created_at}"
}

However, trying to reference workflowContext.otherInfo by using ${workflowContext.otherInfo} will not work, because workflowContext.otherInfo was declared after the Send to Endpoint action triggered the webhook endpoint.