Skip to main content

copyToPayload

A Workflow Engine function that copies a value to the payload in workflowContext for the current object. This can be a specific value, or a substitution for an existing object, such as $custom_info.myvalue.

This function is available as a feature of the Workflow Engine v1.2 download and later.

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

The workflow sweep up filter applies to this function.

Back to Workflow Engine Functions Reference.

Arguments

Workflow Engine function copyToPayload takes the following arguments:

Name

Required

Type

Description

payloadKey

Yes

String

Key in the payload to insert data.

value

Yes

String

Value to insert into payloadKey

Example

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

As part of an alert data export you have a basic payload map defined called "AlertExport", which generates a map with the following keys and values:

{ 
  “alertId”: "$alert_id",
  "summary": "$description" 
}

At export time, you want to include the location, but the data is stored in different places in different alerts: either ci.location.city or ci.location.dc. Additionally you want to add the current time to the alert.

The solution is as follows:

  1. You create two workflows: one to add data from custom_info.location, the other from custom_info.datacentre.

  2. You have already configured default values for these properties, so you can create entry filters based on them. For example, an entry filter of custom_info.location.city != 'Unknown' ensures you are only copying data from alerts that have city set to a non-default value.

  3. You use the copyToPayload function to copy from the correct key into the payload using the following actions:

    1. createPayload configured with the map name (AlertExport).

    2. copyToPayload for alerts within the city, with payloadKey set to "location" and value set to $custom_info.location.city.

    3. copyToPayload with payloadKey set to "currentTime" and value set to $moog_now.

    4. exportViaRest configured with the endpoint name.

This configuration ensures your payload contains the additional data and exports to an external REST endpoint. The final payload is a combination of your base payload and the additional keys you have added to it:

{
  alertId: 11,
  summary: 'Ping fail 10.0.0.1',
  currentTime: 1576154788,
  location: 'London'
}

The actions returns true if the data successfully copies to the payload. If the data did not successfully copy, or the function did not find the payload you specified, it returns false.