DataRow Scripting API

The DataRow API provides typed access to data associated with commands in the current agent data row. It can be used from C# and JavaScript scripts to read values, update values, inspect the current list index, and check whether matching data exists.

Method names follow the conventions of each language: C# uses PascalCase and JavaScript uses lower camel case.

C#

In C#, access the current row through context.DataRow.

Example

C#
public string GetData(RunContext context)
{
    string? product = context.DataRow.GetString("Product");
    int quantity = context.DataRow.GetInt("Quantity");

    context.DataRow.SetBoolean("Processed", true);

    return (product ?? string.Empty) + ": " + quantity;
}

Reading values

Method

Returns

Description

GetInt(string fieldName)

int

Returns the integer value of the specified field.

GetString(string fieldName)

string?

Returns the string value of the specified field. The result can be null.

GetByteArray(string fieldName)

byte[]

Returns the binary value of the specified field.

GetBoolean(string fieldName)

bool

Returns the Boolean value of the specified field.

GetFloat(string fieldName)

float

Returns the floating-point value of the specified field.

GetDateTime(string fieldName)

DateTime

Returns the date-and-time value of the specified field.

Updating values

Method

Description

SetInt(string fieldName, int value)

Sets the specified field to an integer value.

SetString(string fieldName, string value)

Sets the specified field to a string value.

SetByteArray(string fieldName, byte[] value)

Sets the specified field to a binary value.

SetBoolean(string fieldName, bool value)

Sets the specified field to a Boolean value.

SetFloat(string fieldName, float value)

Sets the specified field to a floating-point value.

SetDateTime(string fieldName, DateTime value)

Sets the specified field to a date-and-time value.

Other members

Member

Description

object? this[string fieldName] { get; set; }

Gets or sets a field value without selecting a specific typed method.

GetListIndex()

Returns the current row's list index.

DataExists(string[]? compareFieldNames = null)

Checks whether matching data exists. Optionally restricts the comparison to the specified field names.

C# interface

C#
public interface DataRow
{
    int GetInt(string fieldName);
    string? GetString(string fieldName);
    byte[] GetByteArray(string fieldName);
    bool GetBoolean(string fieldName);
    float GetFloat(string fieldName);
    DateTime GetDateTime(string fieldName);

    void SetInt(string fieldName, int value);
    void SetString(string fieldName, string value);
    void SetByteArray(string fieldName, byte[] value);
    void SetBoolean(string fieldName, bool value);
    void SetFloat(string fieldName, float value);
    void SetDateTime(string fieldName, DateTime value);

    object? this[string fieldName] { get; set; }
    int GetListIndex();
    bool DataExists(string[]? compareFieldNames = null);
}

JavaScript

JavaScript uses lower-camel-case method names. The following example accepts a DataRow instance supplied by the script context.

Example

JavaScript
function readAndUpdateRow(/** @type {DataRow} */ row)
{
    const product = row.getString("Product");
    const quantity = row.getInt("Quantity");

    row.setBoolean("Processed", true);

    return `${product}: ${quantity}`;
}

Reading values

Method

Returns

Description

getInt(fieldName)

number

Returns the integer value of the specified field.

getString(fieldName)

string

Returns the string value of the specified field.

getBoolean(fieldName)

boolean

Returns the Boolean value of the specified field.

getFloat(fieldName)

number

Returns the floating-point value of the specified field.

getDateTime(fieldName)

Date

Returns the date-and-time value of the specified field.

Updating values

Method

Description

setInt(fieldName, value)

Sets the specified field to an integer value.

setString(fieldName, value)

Sets the specified field to a string value.

setBoolean(fieldName, value)

Sets the specified field to a Boolean value.

setFloat(fieldName, value)

Sets the specified field to a floating-point value.

setDateTime(fieldName, value)

Sets the specified field to a JavaScript Date value.

All JavaScript setter methods return void.

Other methods

Method

Returns

Description

getListIndex()

number

Returns the current row's list index.

dataExists(fieldNames?)

boolean

Checks whether matching data exists. Optionally restricts the comparison to the supplied field names.

JavaScript declaration

TypeScript
declare class DataRow {
    getInt(fieldName: string): number;
    getString(fieldName: string): string;
    getBoolean(fieldName: string): boolean;
    getFloat(fieldName: string): number;
    getDateTime(fieldName: string): Date;

    setInt(fieldName: string, value: number): void;
    setString(fieldName: string, value: string): void;
    setBoolean(fieldName: string, value: boolean): void;
    setFloat(fieldName: string, value: number): void;
    setDateTime(fieldName: string, value: Date): void;

    getListIndex(): number;
    dataExists(fieldNames?: string[]): boolean;
}

Language differences

Capability

C#

JavaScript

Integer, string, Boolean, float, and date/time getters and setters

Yes

Yes

Byte-array getter and setter

Yes

Not currently exposed

Untyped field indexer

Yes

Not currently exposed

Nullable string return declared by the interface

Yes

No

Use the getter and setter that matches the field's configured content type.