Table2Object Operator

Overview

The Table2Object operator helps you create an object out of a table. Consider a Data Table with two columns: key and value. Now, imagine that the first row of your table looks like this: key: name and value: Josephine. Then, the next row looks like this: key: age and value: 82. The Table2Object operator takes each row of the table and turns them into key/value pairs in a single object. Continuing with the example, this is how the final object would look: {"name":"Josephine", "age":82}.

The Table2Object operator is located in the Table group at the left of the Data Workflow canvas.

What You'll Learn

In this article, you'll learn:

The Settings of a Table2Object Operator

Here's what the Table2Object operator looks like, along with its Info window:

And here's a breakdown of each setting in the Info window:

Setting

Description

Label

Sets the label for your operator. The label you enter here shows beneath your 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.

Key Column Name

Enter the name (header) of the column that contains the keys you want to use in each key/value pair.

Value Column Name

Enter the name (header) of the column that contains the values you want to use in each key/value pair.

Adding and Configuring a Table2Object Operator

In this use case, let's take a look at how to use the Table2Object operator to create an object out of a table. As the operator's name suggests, the data input source for a Table2Object operator needs to be a table. You'll start by setting up a Data Table component for this use case. The Data Table contains 2 columns: field and value. Each row of the table becomes a key/value pair in the final object.

Here's how the completed use case looks in the Module Builder:

Here's how the completed use case works in Express View, including a peek at the final object in the DevTools Console:

What You Need

To set up this use case, you need:

  • 1 Data Table component

  • 1 Button component

  • 1 Data Workflow component

To set up your Data Workflow, you need:

  • 1 Input operator

  • 1 Table2Object operator

  • 2 Console operators

Configure the Data Table Component

First, you need a table you can turn into an object. A Data Table component is perfect for this. Add a table with two columns: field and value. The values in the field column become the keys in each unique key/value pair. And the values in the value column become the values in each unique key/value pair.

1. Drag and drop a Data Table component onto your canvas.
2. Enter dtTable in the Label and Property Name.
3. Enter the following in the Data Table's dark blue header row:
a. Column A: enter field.
b. Column B: enter value.
4. Complete the rest of the Data Table as follows:

field

value

firstName

Roxane

lastName

Campain

age

37

occupation

librarian

5. Click Save.

Configure the Data Workflow Component

Next, create the Data Workflow that contains the Table2Object operator.

1. Drag and drop a Data Workflow component onto your canvas, placing it below the Data Table.
2. Enter dwfTable2Object in the Label and Property Name.
3. Select Manual from the Trigger Type.

Configure the Input Operator

Let's get your data source, the dtTable Data Table, into your Data Workflow.

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

Setting

Value

Category

Input

Component

dtTable

Required

Yes

Source

Default

Configure the First Console Operator

Add a Console operator. This Console operator helps you see the before of your Data Workflow in the DevTools Console. Later, you'll add an after Console operator to see what the Table2Object operator does.

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

Setting

Value

Category

Console

Label

Before Table2Object

3. Connect the output port (right) of the Input operator to the input port (left) of the Console operator.

Configure the Table2Object Operator

Configure the Table2Object operator. Notice the values you enter in the Info window's Key Column Name and Value Column Name fields. They match the column headers in your Data Table.

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

Setting

Value

Category

Table2Object

Label

 

Key Column Name

field

Value Column Name

value

3. Connect the output port (right) of the Input operator to the input port (left) of the Table2Object operator.

Configure the Second Console Operator

Add a Console operator to help you view the result of your Data Workflow. Notice that the Table2Object operator only outputs to this Console operator. You might want to use a dedicated Output operator when creating applications. Then, you can connect that Output operator to a Hidden component. This lets you store the final object and reference it elsewhere in your application.

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

Setting

Value

Category

Console

Label

After Table2Object

3. Connect the output port (right) of the Table2Object operator to the input port (left) of the Console operator.
4. Click Save.

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 onto your canvas, placing it above the Data Workflow.
2. Enter btnRunDWF in the Property ID.
3. Enter Run Table2Object in the Label Text.
4. Select Event from the Button Action Type.
5. Enter dwfTable2Object in the Trigger on Click field.

6. Click Save.
7. Save your module.

Test your Table2Object operator. Preview your module in Express View and open the DevTools Console. Click the Run Table2Object button and check out what displays in the DevTools Console! It looks something like this:

Changing the Settings of a Table2Object Operator

You can revisit and make changes to this operator.

1. Click the Data Workflow component.

A 5-button toolbar displays above the component on hover-over.

2. Click the (Settings) button to open the Data Workflow canvas.
3. Click the operator to open its Info Window.
4. Make changes to the operator's settings as needed.
5. Click Save.
6. Save your module.

Copying a Table2Object Operator

You can make a copy of your operator using familiar keyboard settings. You can copy and paste an exact copy of your operator, matching all settings.

1. Hover over the Data Workflow component.

A 5-button toolbar displays above the component on hover-over.

2. Click the (Settings) button to open the Data Workflow canvas.
3. Click the operator you want to duplicate.
4. On your keyboard, press Command + C (Mac OS) or Ctrl + C (Windows/Linux) to copy the operator.

TIP  You can copy more than one operator at a time. Hold Command or Ctrl on your keyboard and click all the operators you want to copy. Follow the rest of the steps as usual.

5. On your keyboard, press Command + V (Mac OS) or Ctrl + V (Windows/Linux) to paste the copied operator(s) to the Data Workflow canvas.
6. Click Save.
7. Save your module.

TIP  Did you know you can copy an operator and paste it into a different Data Workflow? You'll use the same steps outlined above.

Removing a Table2Object Operator

Lastly, you can delete this operator from your Data Workflow canvas. You can also use these same steps to delete a connection between two operators.

1. Hover over the Data Workflow component.

A 5-button toolbar displays above the component on hover-over.

2. Click the (Settings) button to open the Data Workflow canvas.
3. Click the operator you want to delete.
4. On your keyboard, press Delete.

NOTE  Once you delete this operator, make sure to connect your remaining operators. If your Data Workflow path doesn't end with an Output or Console operator, your Data Workflow won't work. So, once you delete an operator, make sure to update any remaining paths to end at an Output or Console operator.

5. Click Save.
6. Save your module.

Lab

You can find the completed Table2Object Operator lab here: https://training.unqork.io/#/form/5f472a7cc7aa420218812196/edit.