How to: Validate a Value in an Array Using the Includes Operator

Prev Next

The Includes operator evaluates data for a specific value. If the value is present, it returns true; otherwise, it returns false. This functionality is similar to the Boolean logic check. In some cases, it might be necessary to verify multiple values and convert the data into an array before evaluating the data. For example, consider a data table containing a list of end-users and their respective roles. You might want to confirm that at least one end-user is an administrator. You can convert the role column into an array using the Col2Array operator and use the Includes operator to examine the array.

You’ll find the Includes operator under the Array operators group to the left of the Data Workflow canvas.

Configuration

In this example, you'll learn how to use the Includes operator to confirm a value in an array.

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

Configure the Data Table Component

Begin by adding a Data Table component with a list of end-users and their roles.

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

  2. In the Property ID field, enter dtUsers.

  3. In the data table, enter the following:

    #

    A

    B

    1

    userName

    role

    2

    rmoose

    architect

    3

    kbell

    administrator

    4

    rgreen

    authenticated

    5

    cbing

    client

  4. Click Save Component.

Configure the Data Workflow Component

Now, configure your Data Workflow component. Here, you'll use a Col2Array operator to convert the role column of your data table into an array. The Col2Array operator passes that data to the Includes operator, which determines if it contains the administrator role. Lastly, you'll add a Console operator to view the process.

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

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

  3. From the Trigger Type drop-down, select Watch.

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

    dtUsers

    Required

    Yes

    Source

    Default

Configure the Col2Array Operator

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

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

    Setting

    Value

    Category

    Col2Array

    Label

    Col2Array Role

    Preserve Argument Type

    (unchecked)

    Drop Empty

    No

    Path

    role

    Default Value

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

Configure the Includes Operator

  1. Drag and drop an Includes operator onto your Data Workflow canvas.

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

    Setting

    Value

    Category

    Includes

    Label

    Role Array Includes Administrator

    Value

    administrator

  3. Connect the output port (right) of the Col2Array Role Col2Array operator to the input port (left) of the Role Array Includes Administrator Includes operator.

Configure the 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

    Does the role array include administrator?

  3. Connect the output port (right) of the Role Array Includes Administrator Includes operator to the input port (left) of the Does the role array include administrator? Console operator.

  4. Click Save Component.

  5. Save your module.

Here's how your module looks in the Module Builder:

Because this example runs in the background, you won't see the results unless you open the DevTools Console. Preview your module in Express View and open the DevTools Console, the Includes operator checks the array for the administrator role, and the Does the role array include administrator? Console operator displays the value as true.

The Includes operator evaluates data for a specific value. If the value is present, it returns true; otherwise, it returns false. This functionality is similar to the Boolean logic check. In some cases, it might be necessary to verify multiple values and convert the data into an array before evaluating the data. For example, consider a data table containing a list of end-users and their respective roles. You might want to confirm that at least one end-user is an administrator. You can convert the role column into an array using the Col2Array operator and use the Includes operator to examine the array.

You’ll find the Includes operator under the Array operators group to the left of the Data Workflow canvas.

Configuration

In this example, you'll learn how to use the Includes operator to confirm a value in an array.

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

Configure the Data Table Component

Begin by adding a Data Table component with a list of end-users and their roles.

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

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

  3. In the data table, enter the following:

    #

    A

    B

    1

    userName

    role

    2

    rmoose

    architect

    3

    kbell

    administrator

    4

    rgreen

    authenticated

    5

    cbing

    client

  4. Click Save.

Configure the Data Workflow Component

Now, configure your Data Workflow component. Here, you'll use a Col2Array operator to convert the role column of your data table into an array. The Col2Array operator passes that data to the Includes operator, which determines if it contains the administrator role. Lastly, you'll add a Console operator to view the process.

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

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

  3. From the Trigger Type drop-down, select Watch.

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

    dtUsers

    Required

    Yes

    Source

    Default

Configure the Col2Array Operator

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

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

    Setting

    Value

    Category

    Col2Array

    Label

    Col2Array Role

    Preserve Argument Type

    (unchecked)

    Drop Empty

    No

    Path

    role

    Default Value

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

Configure the Includes Operator

  1. Drag and drop an Includes operator onto your Data Workflow canvas.

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

    Setting

    Value

    Category

    Includes

    Label

    Role Array Includes Administrator

    Value

    administrator

  3. Connect the output port (right) of the Col2Array Role Col2Array operator to the input port (left) of the Role Array Includes Administrator Includes operator.

Configure the 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

    Does the role array include administrator?

  3. Connect the output port (right) of the Role Array Includes Administrator Includes operator to the input port (left) of the Does the role array include administrator? Console operator.

  4. Click Save.

  5. Save your module.

Here's how your module looks in the Module Builder:

Because this example runs in the background, you won't see the results unless you open the DevTools Console. Preview your module in Express View and open the DevTools Console, the Includes operator checks the array for the administrator role, and the Does the role array include administrator? Console operator displays the value as true.