Set Operator

A static image displaying the Data Workflow component's Create Field Operator icon and configuration window.

The Set operator lets Creators add new values to a data structure. Examples of how you can use a Set operator include:

  • Creating a new key/value pair in an object.

  • Creating new row(s) in a table.

  • Adding new key/value pairs in a table row.

You'll find the Set operator in the Table group to the left of the Data Workflow canvas.

Learn more about each setting in the Set operator's Info window:

Setting

Description

Category

Grayed out and non-adjustable setting indicating the operation type.

Label

Sets the label for your operator, displaying below the operator on your Data Workflow canvas.

This field is optional, but set a label if you use more than one of the same operator type. A label helps you identify your operators without opening any Info windows.

Path

Enter the key of the key/value pair you want to create. If you add this key to a specific position in an existing array, it specifies the path to get that position. Use dot notation. For example, [0].name would create a key called name in the 0 index position.

Value

Enter the value for the key/value pair you want to create. You can leave the Value setting blank if you connect another data source to the Set operator's lower input port.

No special formatting is required. If you set a string, you do not need to add quotes around the value.

Input Port Functionality

There are two input ports on the left of the Set operator. Each input port provides a different function:

Upper Input Port

Connect the upper input port to connect to a data source. For example, an Input operator connected to a Data Table component could be the data source. Or, an Input operator could connect to a Create Table operator if you use the Set operator to create rows in a new table.

Lower Input Port

The lower input port connects data to add to your data source. The lower input port is optional as you can define data to add in the Set operator's Info window. However, you can only define simple values to add like a string or a number, in the Info window. To add a more complex data structure, like an array or object, to an existing object, connect the array to the lower input port and the object to the upper input port.

The lower input port can also connect a Create Value operator. Instead of defining the value to add in the Set operator, you'll define the value in the Create Value operator. Enter a value in the Expression/Value field of the Create Value operator. Make sure to use the following formats: =string for strings, and =number for numbers. Then, connect the output port (right) of the Create Value operator to the lower input port (left) of the Set operator.

In this example, use the Set operator to create a key/value pair in an existing object. First, define an object in the Default Value field of a Hidden component. Then, use a JSON Parse operator in the Data Workflow to turn the JSON into an object data structure.

Configure the Hidden Component

Use a Hidden component to create an object where you'll add a key/value pair.

1. In the Module Builder, drag and drop a Hidden component onto your canvas.
2. In the Property ID and Label Text fields, enter sampleObject.
3. In the Default Value field, enter the following: {"firstName":"Minna", "lastName":"Amigon", "age":27}.
4. Click Save Component.

Configure the Data Workflow Component

Next, you'll create the Data Workflow which adds a new key/value pair to your object.

1. Drag and drop a Data Workflow component onto your canvas, placing it below the sampleObject Hidden component.
2. In the Property ID field, enter dwfSet.
3. In the Canvas Label Text field, enter dwfSet.

Configure the Input Operator

1. Drag and drop an Input operator onto your Data Workflow canvas.
2. Configure the operator's Info window as follows:
Info

Category

Input

Component

sampleObject

Required

Yes

Source

Default

Configure the JSON Parse Operator

The JSON Parse operator lets you create the data structure defined in your Hidden component. It parses the JSON and creates the specified object. You cannot add a key/value pair to the object without the JSON Parse operator because you need an object where you can add a key/value pair.

1. Drag and drop a JSON Parse operator onto your Data Workflow canvas.
2. Configure the operator's Info window as follows:
Info

Category

JSON Parse

Label

parseData

Preserve Argument Type

☐ (unchecked)

3. Connect the output port (right) of the sampleObject Input operator to the input port (left) of the parseData JSON Parse operator.

Configure the First Console Operator

1. Drag and drop a Console operator onto your Data Workflow canvas.
2. Configure the operator's Info window as follows:
Info

Category

Console

Label

Before Set

3. Connect the output port (right) of the parseData JSON Parse operator to the input port (left) of the Console operator.

Configure the Set Operator

1. Drag and drop a Set operator onto your Data Workflow canvas.
2. Configure the operator's Info window as follows:
Info

Category

Set

Label

setOccupation

Path

occupation

Value

lawyer
3. Connect the output port (right) of the parseData JSON Parse operator to the upper input port (left) of the setOccupation Set operator.

Configure the Second Console Operator

Add a Console operator to view how the Set operator affects the data in the Data Workflow.

1. Drag and drop a Console operator onto your Data Workflow canvas.
2. Configure the operator's Info window as follows:
Info

Category

Console

Label

After Set

3. Connect the output port (right) of the setOccupation Set operator to the input port (left) of the After Set Console operator.
4. Click Save Component.

Here's how the completed Data Workflow looks:

A static image displaying the completed Data Workflow component.

Configure the Button Component

Finally, create a button to click in Express View that triggers your Data Workflow.

1. Drag and drop a Button component Icon Button component onto your canvas, placing it below the dwfSet Data Workflow.
2. In the Property ID field, enter btwRunDWF.
3. In the Label Text field, enter Run DWF Set.
4. Navigate to the Actions settings.
5. From the Action Type drop-down, select Event.
6. In the On Click field, enter or select dwfSet.

A static image displaying the Button component's configuration settings.

7. Click Save Component.
8. Save your module.

Your completed module looks like the following in the Module Builder:

A static image displaying the completed module.

Preview your module in Express View. Open the DevTools Console and click Run DWF Set.