Has Operator

Overview

The Has operator lets you check if a specific key exists in an object. If the Has operator finds a match, it outputs a Boolean of true. If it doesn't find a match, it outputs a Boolean of false. It's important to note that the Has operator only checks if a key exists. It can't verify the value stored under that key. Or if there's even a value stored under the key. The Has operator also only checks top-level keys. The operator can't check where the key/value pairs are nested. The Has operator can’t check for keys in those embedded objects.

For example, maybe you have a table of internal and external company roles, like Manager and Client. Another column of the table lists the permissions allowed for each role. The permissions are either Administrative or Authenticated. You'll use a Get operator to select the first row of your table. Then you'll use the Has operator to check if there's a permission (if any) assigned to that role. The easiest way to check the permissions is to use the column header as the operator's key. If permissions exist in the first row, the output of the Has operator is a Boolean of true.

It's important to note that the Has operator only works when the input is an object. So, you can't connect a Data Table as an input to the Has operator. Because a table is an array of objects, you'll need to pull out an object to use the Has operator. The Get operator is perfect for retrieving a single row (object) to input into your Has operator.

The following image shows the Boolean false output you'll receive if you input a Data Table directly into a Has operator:

You'll find the Has operator under the Object group to the left of your canvas.

What You'll Learn

In this article, you'll learn:

About the Info Window

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

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.

Path

The Has operator looks for this reference key in the data from the input operator. If the path given to the Has operator matches the key found in the input data, the output is true. If the paths don't match between the previous operator and the Has operator, the output is false.

The Has operator's path must match the input path exactly. If not, then the output is false. For example, let's say the input path is dogNames. If you enter dog as the Has operator path, the output is false. The only acceptable path for this example is dogNames.

Adding a Has Operator

In this use case, you'll use the Has operator to confirm that the roleType key exists in the first row of your Data Table. You'll use a Get operator to select the first row of your table. Then you'll use the Has operator to confirm the key exists. If the key exists in the first row, the output of the Has operator will be true.

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 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 Get operator

  • 1 Has operator

  • 3 Console operators

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

Configure the Data Table Component

First, you'll set up a Data Table to create some sample data. Under the roleName column, you'll enter 4 different roles. Then, under the roleType column, you’ll assign each role either Administrative or Authenticated permissions.

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

Manager

Administrative

Developer

Administrative

Customer

Authenticated

Client

Authenticated

4. Click Save.

Configure the Data Workflow Component

Next, you'll set up your Data Workflow.

1. Drag and drop a Data Workflow component onto your canvas. Place your Data Workflow below your Data Table.
2. Enter dwfHasSingleObject 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

dtRoles

Required

No

Source

Default

Configure the Get Operator

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

Category

Get

Label

Get First Row

Path

[0]

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

Configure the Has Operator

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

Category

Has

Label

Has roleType

Path

roleType

3. Connect the output port (right) of the Get operator to the input port (left) of the Has operator.

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

dtRoles

3. Connect the output port (right) of the Input operator to the input port (left) of the dtRoles Console 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

Get Path [0]

3. Connect the output port (right) of the Get operator to the input port (left) of the Get Path [0] Console operator.

Configure the Third Console Operator

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

Category

Console

Label

Path [0] Has roleType?

3. Connect the output port (right) of the Has operator to the input port (left) of the Path [0] Has roleType? Console operator.
4. Click Save.

Configure the Button Component

Now, let's add a Button component to trigger your Data Workflow.

1. Drag and drop a Button component onto your canvas, placing it below your Data Workflow.
2. Enter btnHasSingleObject in the Property ID field.
3. Enter Get the Has in the Label field.
4. Select Event as the Action Type.
5. Enter dwfHasSingleObject in the Trigger on Click field.

6. Click Save.
7. Save your module.

Preview your module in Express View, and open up the DevTools Console. Click your button and expand your 3 Consoles. First, you'll see your Get operator single out the first row of your Data Table. Now the Has operator will check if this row of the table contains the roleType key. It does, so the output from the Has operator is true.

Changing a Has 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 Has 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 Has 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/605e2154374fb31fae84e83a/edit.