Record function

About Record function

You use a Record function to get a record from a Datasource in order to compare or verify property values against referential values.

getRecord(dsName, keys)

Description

Returns a Datasource object that contains:

  • The first row from the Datasource that corresponds to the filter keys.
  • Null if there is no such row.

The record object properties are the columns defined in the Datasource. This Datasource can be an external database table or an internal InterPlay table.

Syntax getRecord(dsName, …keys)
Return

Record object or null if no record is found.

Parameters

dsName: Datasource name as defined in the Designer.

keys: Variable number of arguments that have the values used for filter keys (in the same order as they are defined in the Designer).

Default operators are used with the filter keys. Default operators are defined in the Datasource Columns (see Default operator ).

Example

This example uses a rule of "modify" type to search a property in a repository and update another property with the corresponding value.

Definition

countryRef = getRecord(“countries”, obj.COUNTRY_CODE)

if countryRef Is Null

then

// the record was not found in the Datasource

err = newError(“invalid.countryCode”, “Invalid country code {0}”, obj.COUNTRY_CODE)

err.field = “COUNTRY_CODE”

else

obj.COUNTRY_NAME = countryRef.NAME

The following example uses a referential table that has the following columns:

  • A (filter key is “No”)
  • B (filter key is ”Yes”, default operator is “=”)
  • startDate (filter key is ”Yes”, default operator is “<”)
  • endDate (filter key is “Yes”, default operator is “>”)

The getRecord function returns the first valid record, which is a record with a current date between startDate and endDate:

Definition

today = today()

rec = getRecord(“some_ds”, obj.PROP_B, today, today)

if rec Is Null

then

err = newError(“invalid.record”, “no record found”);

else

obj.PROP_A = rec.A

Related Links