merge
  • 02 Apr 2024
  • Dark
    Light
  • PDF

merge

  • Dark
    Light
  • PDF

Article Summary

Task Purpose

The merge task allows you to combine data from job variables, static data, and the outgoing variables of tasks to create a new variable. By merging data, you can create new data structures to match the existing parameters of a task, thereby allowing you to reuse existing tasks without programming new tasks. A merge task can combine number, boolean, string, array, and object data types.

When merging data, one of two assignment modes are supported: no keys or unique keys.

Mode Description
No keys assigned to merged data The merge task returns an array of the merged values in a non-deterministic order. See the examples below.
Unique keys assigned to merged data The merge task returns an object with key/value fields as specified. See the examples for this task.

The merge task does not support merging data with partial key assignments or non-unique keys.

Properties

Property Description
Key (optional) Specify a key for each merged value. Supported configurations are either no keys or all unique keys.
Task (required) Specify where to find a variable to merge. You can merge data stored in job variables, a static value, or the outgoing variable of an earlier task.
Variable Specify the data to merge in the Variable field. When the data comes from the job or an earlier task, select the variable from the dropdown list. If the data comes from a static value, type the value in the variable edit box.

How to Configure

First, create a three-element array by merging data returned from three different tasks, and let's assume the tasks return these objects:

{
    "vendor": "Cisco",
    "platforms": [ "3945", "6500" ],
    "chassis": [ "fixed", "modular" ]
}

{
    "release": "15.5"
}

{
    "features": [ "L3VPN", "STP" ]
}

No Keys Assigned

Next, configure the merge task properties with no keys as shown in the datasets below (Figures 1 - 3).

Figure 1: Vendor, Platforms & Chassis Dataset
03-IAP23.1-merge-data-1


Figure 2: Release Data
04-IAP23.1-merge-data-2


Figure 3: Features Dataset
05-IAP23.1-merge-data-3


The merge task returns an array and the order is not deterministic.

Figure 4: Outgoing Array
06-IAP23.1-merge-output


Unique Keys Assigned

Next, create an object by assigning unique keys to each merged value. In addition to the three objects used in the previous example, the merge includes a number, string, boolean, and array.

Configure the merge task properties with unique keys as shown in the datasets below (Figures 5 - 8).

Figure 5: Number
07-IAP23.1-merge-data-4


Figure 6: String
08-IAP23.1-merge-data-5


Figure 7: Boolean
09-IAP23.1-merge-data-6


Figure 8: Array
10-IAP23.1-merge-data-7

The merge task returns this object of specified key/value fields.

{
  "merged_object": {
  "chassis": {
    "vendor": "Cisco",
    "platforms": [
      "3945",
      "6500"
    ],
    "chassis": [
      "fixed",
      "modular"
    ]
  },
  "os-image": {
    "release": "15.5"
  },
  "services": {
    "features": [
      "L3VPN",
      "STP"
    ]
  },
  "number": {
    "myNumber": 13
  },
  "string": {
    "myString": "hello world"
  },
  "boo": {
    "myBoolean": true
  },
  "arr": {
    "myArray": [
      "apple",
      "pear"
    ]
  }
}
}

Reference

For related information, see the merge API reference.


Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.