Col2Array Operator

Overview

The Col2Array operator is part of your toolkit for manipulating data structures. The Col2Array operator converts a column in a table to an array. Remember, a table is an indexed array of objects. The Col2Array operator converts an array of objects into an array of values. In this article, you'll learn how to use the Col2Array operator.

You'll find the Col2Array operator under the Table group at the left of the Data Workflow canvas.

What You'll Learn

In this article, you'll learn:

About the Info Window

Here's what the Col2Array 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.

Drop Empty

When set to NO, where the source column has empty cells, the final array will have indexed, empty values (""). When set to YES, the final array won’t include the empty cells.

Path

Enter the name (column header) of the specific column you want to convert to an array.

Default Value

When Drop Empty is set to NO, any empty cells in the source column get replaced with the default value entered here.

Adding a Col2Array Operator

In this use case, you'll see a simple example of how to use the Col2Array operator. With these basics under your belt, you'll know how to use this operator in more complex use cases. Remember, the data input source for a Col2Array operator must be a table. So for this use case, you'll start by setting up a Data Table component.

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

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

What You'll Need

To set up this use case, you'll need:

  • 1 Data Table component

  • 1 Data Workflow component

  • 1 Button component

To set up your Data Workflow, you'll need:

  • 1 Input operator

  • 1 Col2Array operator

  • 2 Console operators

Configure the Data Table Component

First up, you'll need a table you can turn into an array. A Data Table component is perfect for this.

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

name

Minna

Veronika

Theola

Albina

Ezekiel

5. Click Save.

Configure the Data Workflow Component

Next, you'll create the Data Workflow that will turn your table into an array.

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

Configure the Input Operator

Let's start with getting your data source, the dtTable Data Table, into the 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

This Console operator helps you see the "before" of your Data Workflow in the DevTools Console. Later, you'll add an "after" Console operator, making it easy to see exactly what the Col2Array 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 Col2Array

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

Configure the Col2Array Operator

Now you're ready to set up the Col2Array operator. Notice the value you'll enter in the Info window's Path field. It matches the column header in your Data Table.

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

Setting

Value

Category

Col2Array

Label

 

Drop Empty

Yes

Path

name

Default Value

 

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

Configure the Second Console Operator

Now for one last operator. Here, you'll add a Console operator so you can easily see the "after" of your Data Workflow. You'll notice that the Col2Array operator only outputs to this Console operator. When creating applications, you might also want to use a dedicated Output operator. Then, you could connect that Output operator to a Hidden component. This lets you store the final array 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 Col2Array

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

Configure the Button Component

Finally, let's create a button you can click in Express View to trigger 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 Col2Array in the Label Text.
4. Select Event from the Button Action Type.
5. Enter dwfCol2Array in the Trigger on Click field.

6. Click Save.
7. Save your module.

Now you're ready to test out your Col2Array operator. Preview your module in Express View and open the DevTools Console. Click the Run Col2Array button and check out what appears in the DevTools Console! It should look something like this:

Changing a Col2Array Operator's Settings

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 Col2Array 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.

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.

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 Col2Array 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.

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 Col2Array Operator lab here: https://training.unqork.io/#/form/5f468ef1c7aa420218812100/edit.