Skip to main content

convertObjectList

A Workflow Engine function that extracts key and value pairs from a list of anonymous objects, and creates a new flatter key:value object.

For example, given the following list of anonymous objects:

[
    { 
        name : "test1",
        value : "pass"
    },
    {
        name : "test2",
        value : "pass"
    },
    {
        name : "test3",
        value : "fail"
    }
]

The resulting flatter object would look like:

{
    "test1" : "pass",
    "test2" : "pass",
    "test3" : "fail"
}

The action will return true unless the source object does not exist, or the target (destination) field cannot be updated.

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

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

Back to Workflow Engine Functions Reference.

Duplicate Entries

Whenever a key name is repeated, the values will be consolidated into an array. For example, given a source list:

[            
    {
        "name": "ServiceName",
        "value": "Service1",
        "location": "London"
    },
    {
        "name": "ServiceName",
        "value": "Service2",
        "location": "Paris"
    }
]

and using “name” as the keyName and “value” as the valueName, the resulting object would be:

{
    "ServiceName" : [ "Service1", "Service2"]
}

The values are consolidated for the duplicate key value “ServiceName”.

Asymmetric Objects

If a list contains asymmetric objects (objects where the keys are not consistent), then items missing a keyName will be ignored, and the debug will show which items were unprocessed.

For example, in this list, items 2 and 3 did not contain the keyName “user”:

WARN : [0:Event Workflows][20211221 11:28:13.809 +0000] [actions/convertObjectList.js:172] +|Event Workflows::convertObjectList: Not all items in the list were processed: items 2,3 were not processed|+
WARN : [0:Event Workflows][20211221 11:28:13.809 +0000] [BotUtility.js:885] +|
 ITEMS NOT PROCESSED[2,3] : 
[
    {
        "name": "NotifyUser",
        "userRole": "operator",
        "value": "true",
        "user": "fred@bigco.com"
    },
    {
        "name": "NotifyUser",
        "userRole": "administrator",
        "value": "true",
        "user": "barney@bigco.com"
    },
    {
        "name": "ServiceName",
        "value": "Service1",
        "location": "London"
    },
    {
        "name": "ServiceName",
        "value": "Service2",
        "location": "Paris"
    }
]

For lists with asymmetric objects that require processing, repeat the action with different values for keyName and valueName. Make sure to choose a different destination (the destination is not merged into, it is replaced).

Note

In order to be processed, the objects in the list must have attributes defined for both keyName and valueName. If an object does not have both, it will be ignored.

Arguments

Workflow Engine function convertObjectList takes the following arguments:

Name

Required

Type

Description

listField

yes

string

The CEvent or workflow context field name to use as the source list.

keyName

yes

string

The object attribute within each anonymous object in the list to use as the key in the final object.

valueName

yes

string

The object attribute within each anonymous object in the list to use as the value in the final object for the keyName.

destination

yes

string

The CEvent or workflow context field to write the final object to.

Example

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

Symmetric Objects

Given the following custom_info object:

labels:
[
    {
        “key”: “hostname”,
        “value”: “host0001”
    },
    {
        “key”: “region”,
        “value”: “some_region”
    },
    {
        "key" : "service",
        "value" : "ABC"
    }
]

Create a workflow using the convertObjectList action:

convertObjectList:

  • listField : custom_info.labels

  • keyName : key

  • valueName : value

  • destination : custom_info.eventLabels

In the UI, this would look like:

{"listField":"custom_info.labels","keyName":"key","valueName":"value","destination":"custom_info.eventLabels"}

This would produce the following output object in custom_info.eventLabels:

custom_info : { 
    ...
    "eventLabels": {
        "region": "some_region",
        "hostname": "host0001",
        "service": "ABC"
    },
}

Complex Asymmetric Objects

Given the following custom_info object:

serviceData : 
[
    {
        "name": "NotifyUser",
        "userRole": "operator",
        "value": "true",
        "user": "fred@bigco.com"
    },
    {
        "name": "NotifyUser",
        "userRole": "administrator",
        "value": "true",
        "user": "barney@bigco.com"
    },
    {
        "name": "ServiceName",
        "value": "Service1",
        "location": "London"
    },
    {
        "name": "ServiceName",
        "value": "Service2",
        "location": "Paris"
    }
]

We could extract the “user” and “userRole” as an object using the following parameters:

  • listField : custom_info.serviceData

  • keyName : user

  • valueName : userRole

  • destination : custom_info.userDetails

This would result in the following output object:

custom_info : {
    ...
    "userDetails": {
        "barney@bigco.com": "administrator",
        "fred@bigco.com": "operator"
    }
}

Had we used the following parameters with the same data:

  • listField : custom_info.serviceData

  • keyName : name

  • valueName : user

  • destination : custom_info.userDetails

The resulting object would be:

custom_info : {
    ...
    "userDetails": {
        "NotifyUser": ["fred@bigco.com","barney@bigco.com"]
    },
}

The common key value “NotifyUser” has values for both records.