Skip to main content Skip to complementary content

Variable block

Use a Variable block if you want to work with variables in your Data Blend. A variable has a name and type, and it can store data while the Datan automation is running.

Please note that variables are not stored in a database. When the Datan automation is completed, the variable data is erased, it is not persisted across runs.

Variables are typically used to temporarily store and transform data during the execution of the Data Blend.

The Variable block.

The Variable block.

Settings pane of this block:

The Settings pane of the Variable block.

The Settings tab of the Variable block. There is a field to set the variable name and type, and a field to set the value.

Creating variables

Click the link Manage variables in the Settings pane of this block to create variables.

Variable Type

Variables have a name and have a type. The type defines the type of data it can hold. The following types are available:

  • String: any text
  • List: a list of items (records)
  • Table: a list of a list of items (the table consists of a list of rows, and each row is a list of items). A table is also called a matrix.
  • Object: any JSON object

Examples in JSON format for each type:

  • String: "This is text"
  • List: [ { "id": 123 }, { "id": "356" }, "abc" ]
  • Table: [ [ "item 1", "item 2", "item 3"], [ "item 4", "item 5", "item 6"] ]
  • Object: { "name": "Bill", "id": 123 }

The type of a variable cannot be changed after it has been created.

Operations on variables

On the Settings pane of the Variable block, you can add one or more operations. The operations are executed on the variable, when the Block itself is executed inside the Datan automation flow.

The operations are executed one by one, top to bottom.

The following operations are available for variables of type String (text):

  • Empty: make the variable empty (set it equal to an empty text)
  • Set value: set the value of the variable (a text)
  • Append: add extra text at the end of the variable

The following operations are available for variables of type List:

  • Empty: make list empty
  • Add item: add an item (e.g. a record = object) to the list
  • Merge other list into list: add all the items of another list to the current list

The following operations are available for variables of type Table:

  • Empty: make table empty
  • Add row: add a row to the table, the input should be a list of items (e.g. a list of strings)

The following operations are available for variables of type Object:

  • Empty: make object empty
  • Set equal to: set object equal to any other object (JSON structure)
  • Set key/values: set individual keys and their value (the value can be any other JSON structure: object, text, list...)
  • Merge other object into this object: merge another object into the current object. If the same key exists in both objects, a conflict exists. You can configure the On conflict behaviour: either ignore the conflicting key (this means it will not be merged into the current object) or rename keys (this means a new key key_1 will be added into the current object)
  • Rename key: rename a key in the object

Pattern: building a list of objects using variables

A common pattern is building a list with objects, where objects have specific key/values.

For this pattern, you have to create two variables, one of type List and one of type Object. In this example we named these variables: MyList and MyObject.

Make sure to empty MyList first, because this pattern might be used inside an overall loop and could still contain items. Do this by adding the Operation Empty MyList to the variable MyList:

Emptying a list variable.

an automation consisting of a Start block, a Variable: MyList block, a Loop block containing a Variable: MyObject block and a Variable: MyList block, and an Output block. The first Variable block is selected. Empty MyList has been added.

Next, loop over some data. In the loop you will build the MyObject object. Make sure to make MyObject empty first by adding the Operation Empty MyObject. Next add the operation Set key/values of MyObject. Add one or more keys and values. In this example we added key1 and key2, and we are using data from the loop as the value:

Emptying, then filling an object variable.

As above, but the Variable: MyObject block is selected. It is set to empty the object variable, then add a key and a value from the loop.

Next, add MyObject to the list MyList, by using the Operation Add item to MyList on the variable MyList:

Adding an object to a list.

As above, but the second Variable: MyList block is selected. MyObject is added to MyList.

Finally, you can use the list MyList below the loop:

Outputting a list.

As above, but the Output block is selected. The data output is the MyList list.

This is what MyList will look like in raw JSON:

[
  {
     "key1": "some value 1",
     "key2: "some other value 2"
  },
  {
     "key1": "some value 2",
     "key2: "some other value 2"
  }
]

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!