Data Selection Functions

A data selection function selects data from a source. The source can be either a selection or results of a query. The function returns a table of data, where each column has a name, and each row has an index, starting with 0. From the table, you can select one or more rows, one or more columns, or a cell to include in your interaction.

In cases where multiple rows or columns of data are selected, the function returns a two-dimensional array. When a single row or single column is selected, the function returns a one-dimensional array. When a cell is selected, the function returns a scalar value. The function returns null if the source is empty. If the function tries to select data that doesn’t exist, an interaction error occurs. For example, the table only has two rows, but you try to select data from the third row.

cell Function 

Returns a single cell of data as a scalar, like "This salesperson rocks", 2, or null. An error occurs if the rowIndex isn’t an integer, the columnName isn’t a string, or the cell doesn’t exist in the table.

Syntax 

1cell(source, rowIndex, columnName)

Arguments 

ArgumentDescription
source(Required) Specify the name of the query and selection or result.
rowIndex(Required) Specify the row using its index. Row index starts at 0.
columnName(Required) Specify the column name.

This example is based on the myStep source query. Assume that myStep.selection retrieves these rows from the query.

1[
2    {stateName: ‘CA’, Amount:100},
3    {stateName: ‘TX’, Amount:200},
4    {stateName: ‘OR’’, Amount:300},
5    {stateName: ‘AL’, Amount:400},
6]

Although CRM Analytics doesn’t store this data as a table, let’s show the data in this format to make it easier to understand the example.

(row index)stateNameAmount
0CA100
1TX200
2OR300
3AL400

Example 

Function:

1cell(myStep.selection, 1, "stateName")

Output:

1"TX"

column Function 

Returns one column of data as a one-dimensional array or multiple columns of data as a two-dimensional array.

Syntax 

1column(source, [columnNames...])

Arguments 

ArgumentDescription
source(Required) Specify the name of the query and selection or result.
columnNames(Required) Specify an array of column names. The order of the listed columns affects the order that the columns appear in the output. The order is important for serialization functions. For example, the asOrder function requires the first element to be a field name and the second to be the direction.

These examples are based on the myStep source query. Assume that myQuery.selection retrieves these rows from the query.

1[
2    {stateName: ‘CA’, Amount:100},
3    {stateName: ‘TX’, Amount:200},
4    {stateName: ‘OR’’, Amount:300},
5    {stateName: ‘AL’, Amount:400},
6]

Examples 

Although CRM Analytics doesn’t store this data as a table, let’s show the data in this format to make it easier to understand the examples that follow.

(row index)stateNameAmount
0CA100
1TX200
2OR300
3AL400

Function:

1column(myStep.selection, ["stateName"])

Output:

1["CA", "TX", "OR", "AL"]

Function:

1column(myStep.selection, [])

Output:

1[ ["CA", "TX", "OR", "AL"], ["100", "200”," "300", "400"] ]

row Function 

Returns one row of data as a one-dimensional array or multiple rows as a two-dimensional array. For selection interactions, you typically use this function to return the first row or all rows. For results interactions, you might want specific rows. To determine the row index, display the query results in a values table.

Syntax 

1row(source), [rowIndices...], [columnNames...])

Arguments 

ArgumentDescription
source(Required) Specify the name of the query and selection or result.
rowIndices(Required) Specify an array of row indices, where each element of the array identifies a row. Row index 0 identifies the first row. To include all rows, specify an empty array.
columnNames(Optional) Specify an array of column names to select and order them. If not specified, all columns are selected and every row has the same order of columns. However, that order isn’t guaranteed to be the same across different queries.

These examples are based on the myStep source query. Assume that myStep.selection retrieves these rows from the query.

1[
2    {stateName: ‘CA’, Amount:100},
3    {stateName: ‘TX’, Amount:200},
4    {stateName: ‘OR’’, Amount:300},
5    {stateName: ‘AL’, Amount:400},
6]

Examples 

Although CRM Analytics doesn’t store this data as a table, let’s show the data in this format to make it easier to understand the examples that follow.

(row index)stateNameAmount
0CA100
1TX200
2OR300
3AL400

Function:

1row(myStep.selection, [0], ["Amount"])

Output:

1["100"]

Function:

1row(myStep.selection, [0,2], [])

Output:

1[ ["CA", "100"], ["OR", "300"] ]

Function:

1row(myStep.selection, [], ["stateName"])

Output:

1[ ["CA"], ["TX"], ["OR"], ["AL"] ]

Function:

1row(myStep.selection, [0,2], ["stateName", "Amount"])

Output:

1[ ["CA", "100"], ["OR", "300"] ]