Skip to main content

addToContext

A Workflow Engine function that adds a specified value to a specified key in the workflow context. The key can be nested (example: key1.key2) and the value can be any acceptable value, including full substitution using the macro language. Subsequent actions place the key and value into the workflow context for use.

This function is available as a feature of the Add-ons v2.2 download and later.

This function is available for event, alert, and Situation workflows.

Back to Workflow Engine Functions Reference.

Arguments

Workflow Engine function addToContext takes the following arguments:

Name

Required

Type

Description

key

yes

string

The key name. Compound keys are added as nested objects.

value

yes

string

The value to set the key to. The value can include native values (strings, numbers) or substituted values.

Example

The following example demonstrates typical use of Workflow Engine function addToContext.

To add a simple value to the workflowContext

  • key : myKey

  • value : A simple value, 1, 2, 3, 4

The UI translates your settings to the following JSON:

{"key":"myKey","value":"A simple value 1, 2, 3, 4"}

To add a JSON object (in this case a list, or array), use the macro language:

  • key : myKey1

  • value : $TO_JSON( [ 1, 2, 3, 4, 5, ] )

The UI shows this as:

{"key":"myKey2","value":"$TO_JSON([1,2,3,4,5])"}

To add a substituted value from the in-scope object (in this case a Situation):

  • key : myKey3

  • value : A substitution $(sig_id) with an expansion $EXPAND(internal_priority)

The UI shows this as:

{"key":"myKey3","value":"A substitution $(sig_id) with an expansion $EXPAND(internal_priority) "}

To add a nested object, use a dotted notation in the key name:

  • key : myKey4.myKey5

  • value : $TO_JSON({ "a" : "b" , "c" : [ 1, 2 ,3, 4, 5] })

The UI shows this as:

{"key":"myKey4.myKey5","value":"$TO_JSON({ \"a\" : \"b\" , \"c\" : [ 1, 2 ,3, 4, 5] })"}

After the above actions, the workflowContext looks like this:

WORKFLOW CONTEXT: SITUATION: 186 :  : 
{
    "myKey": "A simple value 1, 2, 3, 4",
    "myKey2": [
        1,
        2,
        3,
        4,
        5
    ],
    "myKey3": "A substitution 186 with an expansion Critical ",
    "myKey4": {
        "myKey5": {
            "a": "b",
            "c": [
                1,
                2,
                3,
                4,
                5
            ]
        }
    }