Includes Operator: Checking an Array for a Value

Overview

Sometimes you'll want to pass more than just a single value to an Includes operator. To do that, you'll need to convert your data to an array. Let's say you have a data table with a list of users and their roles. You want to make sure that at least one of those users has the role of administrator. First, you'll convert that column of your data table using a Col2Array operator. Then, you'll use an Includes operator to read that data. Let's take a look.

Here's how your module will look in the Module Builder:

This use case works behind the scenes, so you won't see anything in Express View outside of the DevTools Console. So, here's a sneak peek at that:

What You'll Learn

In this article, you'll learn how to use the Includes operator when checking an array for a value.

What You'll Need

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

  • 1 Data Table component

  • 1 Data Workflow component

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

  • 1 Input operator

  • 1 Col2Array operator

  • 1 Includes operator

  • 1 Console operator

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

Configuration

Configure the Data Table Component

First, let's add your list of users. You'll use a Data Table component for that.

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

rmoose

architect

kbell

administrator

rgreen

authenticated

cbing

client

4. Click Save.

Configure the Data Workflow

Now, let's set up your Data Workflow. Here, you'll use a Col2Array operator to turn the role column of your data table into an array. The Col2Array operator then passes that data to the Includes operator, which verifies that the data holds administrator. Finally, you'll add a Console operator so you can see all of this happen behind the scenes.

1. Drag and drop a Data Workflow component onto your canvas. Place your Data Workflow below your Data Table.
2. Enter dwfIncludesArray in the Canvas Label Text and Property Name fields.
3. Select Watch as the Trigger Type.

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

dtUsers

Required

Yes

Source

Default

Configure the Col2Array Operator

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

Setting

Value

Category

Col2Array

Label

Col2Array Role

Drop Empty

No

Path

role

Default Value

 

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

Configure the Includes Operator

1. Drag and drop an Includes operator onto your Data Workflow canvas.
2. Configure the Includes 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 operator to the input port (left) of the Includes operator.

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

Does the role array include administrator?

3. Connect the output port (right) of the Includes operator to the input port (left) of the Console operator.
4. Click Save.
5. Save your module.

Now it's time to preview your module. Preview your module in Express View and open the DevTools Console. You'll see your Does the role array include administrator? Console shows a value of true.

Lab

You can view this complete use case here: https://training.unqork.io/#/form/604a638cc63f4c0242cb5089/edit.