Has Operator

Prev Next

The Has operator checks whether a specific key exists in an object. When a match is found, the operator outputs a Boolean value of true; otherwise, the output is false.

It’s important to remember that the Has operator only verifies the existence of a key. It does not validate the value stored under that key or determine whether the key has a defined value. Additionally, the Has operator only searches top-level keys. It cannot detect keys nested in other objects.

Below are some considerations when using the Has operator:

  • The Has operator only works with objects as inputs.

  • You cannot connect a Data Table component directly to the Has operator because a table is an array of objects.

  • To use the Has operator with a table, first extract a single object using the Get operator.

  • The Get operator retrieves one row (object) from the array, which you can then input into the Has operator for evaluation.

Let’s say you have a Data Table listing internal and external company roles, such as Manager and Client. Another column in the table defines the permissions for each role, either Administrative or Authenticated.

  1. Use a Get operator to retrieve the first row from the table.

  2. Then connect the Has operator to check if a permission key exists for that role.

    In this setup, you’ll use the column header for example, permissions as the operator’s key.

  3. If the first row contains a permissions key, the Has operator outputs true. If it doesn’t, the output is false.

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

About the Info Window

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

Preserve Argument Type

When selected, this setting ensures the argument data type is respected when the operator executes.

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 example, you'll use the Has operator to confirm that the roleType key exists in the first row of your Data Table component. You'll use a Get operator to select the first row of the table, then use the Has operator to confirm if the key exists. If the key exists in the first row, the output of the Has operator will be true. If not, it’ll be false.

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

Configure the Data Table Component

Start by configuring a Data Table component to create some sample data with roleName  and roleType columns. Now, enter four different roles in roleName column and assign each role either Administrative or Authenticated permissions in the roleType column.

  1. In the Module Builder, drag and drop a Data Table component onto your canvas.

  2. In the Property ID field, enter dtRoles.

  3. In the data table, enter the following:

    roleName

    roleType

    Manager

    Administrative

    Developer

    Administrative

    Customer

    Authenticated

    Client

    Authenticated

  4. Click Save Component.

Configure the Data Workflow Component

Next, set up your Data Workflow and use the Has operator to confirm if the key exists. If the key exists in the first row, the output of the Has operator will be true. If not, it’ll be false.

  1. Drag and drop a Data Workflow component onto your canvas, placing it below your dtRoles Data Table component.

  2. In the Property ID and Canvas Label Text fields, enter dwfHasSingleObject.

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:

    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 operator's Info window as follows:

    Setting

    Value

    Category

    Get

    Label

    Get First Row

    Path

    [0]

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

Configure the Has Operator

  1. Drag and drop a Has operator onto your Data Workflow canvas.

  2. Configure the operator's Info window as follows:

    Setting

    Value

    Category

    Has

    Label

    Has roleType

    Path

    roleType

  3. Connect the output port (right) of the Get First Row Get operator to the input port (left) of the Has roleType Has 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:

    Setting

    Value

    Category

    Console

    Label

    dtRoles

  3. Connect the output port (right) of the dtRoles 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 operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Get Path [0]

  3. Connect the output port (right) of the Get First Row 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 operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Path [0] Has roleType?

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

  4. Click Save Component.

Configure the Button Component

Now, configure a Button component that you can click in Express View to trigger your Data Workflow.

  1. Drag and drop a Button component onto your canvas, placing it below your dwfHasSingleObject Data Workflow component.

  2. In the Property ID field, enter btnHasSingleObject.

  3. In the Label Text field, enter Get the Has.

  4. From the Action Type drop-down, select Event.

  5. In the Trigger On Click field, enter dwfHasSingleObject.

  6. Click Save Component.

  7. Save your module.

Here's how the completed example looks in the Module Builder:

Here's how the completed example works in Express View, including a peek at the DevTools Console:

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

The Has operator checks whether a specific key exists in an object. When a match is found, the operator outputs a Boolean value of true; otherwise, the output is false.

It’s important to remember that the Has operator only verifies the existence of a key. It does not validate the value stored under that key or determine whether the key has a defined value. Additionally, the Has operator only searches top-level keys. It cannot detect keys nested in other objects.

Below are some considerations when using the Has operator:

  • The Has operator only works with objects as inputs.

  • You cannot connect a Data Table component directly to the Has operator because a table is an array of objects.

  • To use the Has operator with a table, first extract a single object using the Get operator.

  • The Get operator retrieves one row (object) from the array, which you can then input into the Has operator for evaluation.

Let’s say you have a Data Table listing internal and external company roles, such as Manager and Client. Another column in the table defines the permissions for each role, either Administrative or Authenticated.

  1. Use a Get operator to retrieve the first row from the table.

  2. Then connect the Has operator to check if a permission key exists for that role.

    In this setup, you’ll use the column header for example, permissions as the operator’s key.

  3. If the first row contains a permissions key, the Has operator outputs true. If it doesn’t, the output is false.

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

About the Info Window

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

Preserve Argument Type

When selected, this setting ensures the argument data type is respected when the operator executes.

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 example, you'll use the Has operator to confirm that the roleType key exists in the first row of your Data Table component. You'll use a Get operator to select the first row of the table, then use the Has operator to confirm if the key exists. If the key exists in the first row, the output of the Has operator will be true. If not, it’ll be false.

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

Configure the Data Table Component

Start by configuring a Data Table component to create some sample data with roleName  and roleType columns. Now, enter four different roles in roleName column and assign each role either Administrative or Authenticated permissions in the roleType column.

  1. In the Module Builder, drag and drop a Data Table component onto your canvas.

  2. In the Label and Property Name fields, enter dtRoles.

  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, set up your Data Workflow and use the Has operator to confirm if the key exists. If the key exists in the first row, the output of the Has operator will be true. If not, it’ll be false.

  1. Drag and drop a Data Workflow component onto your canvas, placing it below your dtRoles Data Table component.

  2. In the Canvas Label Text and Property Name fields, enter dwfHasSingleObject.

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:

    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 operator's Info window as follows:

    Setting

    Value

    Category

    Get

    Label

    Get First Row

    Path

    [0]

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

Configure the Has Operator

  1. Drag and drop a Has operator onto your Data Workflow canvas.

  2. Configure the operator's Info window as follows:

    Setting

    Value

    Category

    Has

    Label

    Has roleType

    Path

    roleType

  3. Connect the output port (right) of the Get First Row Get operator to the input port (left) of the Has roleType Has 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:

    Setting

    Value

    Category

    Console

    Label

    dtRoles

  3. Connect the output port (right) of the dtRoles 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 operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Get Path [0]

  3. Connect the output port (right) of the Get First Row 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 operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Path [0] Has roleType?

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

  4. Click Save.

Configure the Button Component

Now, configure a Button component that you can click in Express View to trigger your Data Workflow.

  1. Drag and drop a Button component onto your canvas, placing it below your dwfHasSingleObject Data Workflow component.

  2. In the Property ID field, enter btnHasSingleObject.

  3. In the Label Text field, enter Get the Has.

  4. From the Action Type drop-down, select Event.

  5. In the Trigger On Click field, enter dwfHasSingleObject.

  6. Click Save & Close.

  7. Save your module.

Here's how the completed example looks in the Module Builder:

Here's how the completed example works in Express View, including a peek at the DevTools Console:

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