Convert Field Operator

Overview

The Convert Field operator lets you take keys from a data set and convert the values they hold. You can convert the values in these fields to numbers, integers, or strings.

NOTE  Whole objects can't be converted. You can only convert fields within objects. If a whole object is passed to the Convert Field operator, it will return a value of [object,object].

Before looking more closely at this operator, here's an overview of these 3 data types:

  • Number: This data type is for numbers, and only for numbers. So, we wouldn't classify the word ten as a number. But we would classify the number 10 under the number data type. This data type also allows for the use of decimals, differentiating it from the next data type. When converting to a Number data type, any original values with non-numerical characters show as NaN (Not a Number) in your final data. To avoid lost data, ensure that your original data excludes non-numerical characters.

  • Integer: This data type is also for numbers, but it doesn't allow for decimals. So, when converting to an integer, a number will only include what falls before the decimal. When converting to an Integer data type, any original values with non-numerical characters show as 0 in your final data. To avoid lost data, ensure that your original data excludes non-numerical characters.

  • String: You'll sometimes see strings referred to as text. But this doesn't mean strings can only contain letters. Data stored as a string can include numbers, letters, symbols, and spaces. Strings can be as short as a few letters or contain entire paragraphs.

The Unqork Designer Platform handles each data type a little differently. And sometimes you'll need to convert the data collected in a field from one type to another. The Convert Field operator lets you convert entire columns in a data table or fields in an array at once.

You’ll find the Convert Field operator under the Table group at the left of the Data Workflow canvas.

Similar Data Workflow Operators

The Convert Field operator is similar to the Convert Value operator. Here are the operators compared: 

  • Convert Field operator: Converts all values in a specified key of a data set. This is best if you're working with large amounts of data that need conversion.

  • Convert Value operator: Converts a single value passed to it. This is best if you're only working with a single key/value pair of data.

What You'll Learn

In this article, you'll learn:

The Convert Field operator lets you convert entire columns in a data table or fields in an array at once. That's when the Convert Field operator is useful.

About the Info Window

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

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

Setting

Description

Category

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

Label

The name applied to the operator. This label displays within the workflow. Labels should be user-friendly and well associated with the role of the operator.

Cast To

The final data type you want after the operator performs its conversion. Here, you'll find a drop-down with the following options:

  • Number

  • Integer

  • String

Keys

Enter the key for any data you want the operator to convert. When working with a data table, the key is the name of the column you want converted. You can convert more than one key using a single operator. Separate each new key in this field by a comma.

You can also set your Keys using an argument. To do that, connect an Input operator to the operator's argument port. Then, enter _arg in this field. Remember that the value passed using an argument must still match a key in your data set.

Adding a Convert Field Operator

To show this operator in action, let's look at an example. Say you have a data table with account information and each field (column) is stored as a string. To make data processing easier, you want your Account Value field to have a number data type. To perform this conversion, you'll use a Convert Field operator.

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

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

What You'll Need

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

  • 1 Data Table component

  • 1 Button component

  • 1 Data Workflow component

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

  • 1 Input operator

  • 1 Convert Field operator

  • 2 Console operators

NOTE  These instructions assume you have a new module open, saved, and with a title.

Configure the Data Table Component

First, let's set up your account data. You'll use a Data Table component for that.

1. In the Module Builder, drag and drop a Data Table component onto your canvas.
2. Enter dtAccounts in the Label and Property Name fields.
3. In the data table, enter the following:

firstName

certification accountValue

Blair

aws solutions architect

$1000000

JJ

 

$6789.00

Jim

 

1000000

Evan

aws developer

null

Charlotte

aws security

5000000

Amy

aws database

$5439294

Brian

aws machine learning

$178.90

Rupert

null

195.78

Emily

aws networking specialty

nine hundred thousand

4. Click Save.

Configure the Data Workflow Component

Next, let's set up your Data Workflow. You'll use an Input operator to bring in your data. Then, you'll use a Convert Field operator with the Cast To field set to Number. You'll also include 2 Console operators so you can see what your data looks like before and after the conversion.

1. Drag and drop a Data Workflow component onto your canvas. Place your Data Workflow below your Data Table.
2. Enter dwfConvertFieldNumber in the Canvas Label Text and Property Name fields.

Configure the Input Operator

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

Setting

Value

Category

Input

Component

dtAccounts

Required

Yes

Source

Default

Configure the First Console Operator

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

Setting

Value

Category

Console

Label

Before

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

Configure the Convert Field Operator

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

Setting

Value

Category

Convert To

Label

Convert accountValue to Number

Cast To

Number

Keys

accountValue

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

Configure the Second Console Operator

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

Setting

Value

Category

Console

Label

After

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

Configure the Button Component

Now, let's add a Button component to trigger the whole operation.

1. Drag and drop a Button component onto your canvas. Place your Button below your Data Workflow.
2. Enter btnConvert in the Property ID field.
3. Enter Convert to Number in the Label field.
4. Select Event as the Action Type.
5. Enter dwfConvertFieldNumber in the Trigger on Click field.

6. Click Save.
7. Save your module.

Now it's time to test your work. Preview your module in Express View and open the DevTools Console. Now, click your Convert to Number button. You'll see your Before and After Consoles in the DevTools Console. In your Before Console, you'll see the data as you entered it into your Data Table. And in your After Console, you'll see your account values have been converted to numbers. Remember, NaN means Not a Number, and you'll see this anywhere your original data included non-numerical characters.

Changing a Convert Field 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 Convert Field 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 Convert Field 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 view this complete use case here: https://training.unqork.io/#/form/6052584675657f0373bc5103/edit.