Record Functions (Dynamic Field Access)

List of Functions
comparegetRecordProperties
copyByNamegetStringValue
copyByPositiongetValueAsString
getBoolValueisNull
getByteValuelength
getDateValueresetRecord
getDecimalValuesetBoolValue
getFieldIndexsetByteValue
getFieldLabelsetDateValue
getFieldNamesetDecimalValue
getFieldPropertiessetIntValue
getFieldTypesetLongValue
getIntValuesetNumValue
getLongValuesetStringValue
getNumValue 

These functions are to be found in the Functions tab, section Dynamic field access library inside the Transform Editor.

compare

integer compare(record record1, integer fieldIndex1, record record2, integer fieldIndex2);

integer compare(record record1, string fieldName1, record record2, string fieldName2);

The compare() function compares two fields of given records.

The fields are identified by their index (integer - 0 is the first field) or name (string). The function returns an integer value which is either:

  1. < 0 ... field2 is greater than field1

  2. > 0 ... field2 is lower than field1

  3. 0 ... fields are equal

If one of the given record has a null reference, the function fails with an error.

Compatibility

The compare(reference,integer,reference,integer) and compare(reference,string,reference,string) functions are available since CloverETL 3.2.0.

Example 68.192. Usage of compare

$out.0.field1 = $in.0.field1 + 1;
$out.0.field2 = $in.0.field1;
$out.0.field3 = $in.0.field1 - 1;

$out.0.field5 = compare($in.0, 0, $out.0, 0);  // returns -1
$out.0.field6 = compare($in.0, 0, $out.0, 1);  // returns  0
$out.0.field7 = compare($in.0, 0, $out.0, 2);  // returns  1

$out.0.field8 = compare($in.0, "field1", $out.0, "field1");  // returns -1
$out.0.field9 = compare($in.0, "field1", $out.0, "field2");  // returns  0
$out.0.field10 = compare($in.0, "field1", $out.0, "field3"); // returns  1

copyByName

void copyByName(record to, record from);

The copyByName() function copies data from the input record to the output record based on field names. Enables mapping of equally named fields only.

If a record specified as a first argument has a null reference, the function fails with an error.

Compatibility

The copyByName(reference,reference) function is available since CloverETL 3.2.2 or earlier.

Example 68.193. Usage of copyByName

There are two records. The input record has fields city, countryCode and phone. The output record has fields countryCode, phone and email.

The function copyByName($out.0, $in.0) copies fields countryCode and phone.


See also:  copyByPosition

copyByPosition

void copyByPosition(record to, record from);

The copyByPosition() function copies data from the input record to the output record based on fields order. The number of fields in output metadata decides which input fields (beginning the first one) are mapped.

If a record specified as a first argument has a null reference, the function fails with an error.

Compatibility

The copyByPosition(reference,reference) function is available since CloverETL 3.2.2 or earlier.

Example 68.194. Usage of copyByPosition

There are two records. The input record has fields field1, field2 and field3. The output record has fields firstField and lastField. The function copyByPosition($out.0, $in.0) copies value from field1 to firstField and from field2 to lastField.


See also:  copyByName

getBoolValue

boolean getBoolValue(record record, integer fieldIndex);

boolean getBoolValue(record record, string fieldName);

The getBoolValue() function returns the value of a boolean field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getBoolValue(reference, integer) and getBoolValue(reference,string) functions are available since CloverETL 3.2.0.

Example 68.195. Usage of getBoolValue

There is a record with with fields field1, field2 and field3 and values [true, false, true].

The function getBoolValue($in.0, 1) returns false as second field of record is set to false.

The function getBoolValue($in.0, "field1") returns true.


See also:  getByteValue, getDateValue, getDecimalValue, getIntValue, getLongValue, getNumValue, getStringValue, getValueAsString, setBoolValue

getByteValue

byte getByteValue(record record, integer fieldIndex);

byte getByteValue(record record, string fieldName);

The getByteValue() function returns the value of a byte field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getByteValue(record,integer) and getByteValue(record,string) functions are available since CloverETL 3.2.0.

Example 68.196. Usage of getByteValue

There is a record with fields field1,field2 and field3 containing values oak, larch and pine.

The function getByteValue($in.0, 0) returns oak.

The function getByteValue($in.0, 1) returns larch.

The function getByteValue($in.0, "field3") returns pine.


See also:  getBoolValue, getDateValue, getDecimalValue, getIntValue, getLongValue, getNumValue, getStringValue, getValueAsString, setByteValue

getDateValue

date getDateValue(record record, integer fieldIndex);

date getDateValue(record record, string fieldName);

The getDateValue() function returns the value of a date field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getDateValue(reference,integer) and getDateValue(reference,string) functions are available since CloverETL 3.2.0.

Example 68.197. Usage of getDateValue

There is a record having fields date1, date2, date3 and date4 with values 2010-10-10, 2011-11-11, 2012-12-12 and null.

The function getDateValue($in.0, 0) returns 2010-10-10.

The function getDateValue($in.0, 3) returns null.

The function getDateValue($in.0, 8) fails with an error.

The function getByteValue($in.0, "field3") returns 2012-12-12.

The function getByteValue($in.0, "field9") fails with an error. Field field9 is not present in the record.


See also:  getBoolValue, getByteValue, getDecimalValue, getIntValue, getLongValue, getNumValue, getStringValue, getValueAsString, setDateValue

getDecimalValue

decimal getDecimalValue(record record, integer fieldIndex);

decimal getDecimalValue(record record, string fieldName);

The getDecimalValue() function returns the value of a decimal field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getDecimalValue(reference,integer) and getDecimalValue(reference,string) functions are available CloverETL 3.2.0.

Example 68.198. Usage of DecimalValue

There is a record having fields field1, field2 and field3 with values 1.01D, 20.52D and 100.75D.

The function getDecimalValue($in.0, 0) returns 1.01.

The function getDecimalValue($in.0, "field3") returns 100.75.


See also:  getBoolValue, getByteValue, getDateValue, getIntValue, getLongValue, getNumValue, getStringValue, getValueAsString, setDecimalValue

getFieldIndex

integer getFieldIndex(record record, string field);

The getFieldIndex() function returns the index (zero-based) of a field which is identified by its name. If the field name is not found in the record, the function returns -1.

If a given record has a null reference, the function fails with an error.

Compatibility

The getFieldIndex(reference,string) function is available since CloverETL 3.2.0.

Example 68.199. Usage of getFieldIndex

There is a record having fields field1, field2 and field3.

The function getFieldIndex($in.0, "field1") returns 0.

The function getFieldIndex($in.0, "field123") returns -1.


See also:  getFieldLabel, getFieldName, getFieldType

getFieldLabel

string getFieldLabel(record record, integer field);

The getFieldLabel() function returns the label of a field which is identified by its index. Please note a label is not a field's name, see Field Name vs. Label vs. Description.

If a given record has a null reference, the function fails with an error.

Compatibility

The getFieldLabel(record,integer) and getFieldLabel(record,string) functions are available since CloverETL 3.2.0.

Example 68.200. Usage of getFieldLabel

There is a record having fields field1 and field2 with field labels The first field and The second field.

The function getFieldLabel($in.0, "field1") returns The first field.

The function getFieldLabel($in.0, "field41") fails with an error.


See also:  getFieldIndex, getFieldName, getFieldType

getFieldName

string getFieldName(record argRecord, integer index);

The getFieldName() function returns the name of the field with the specified index. Fields are numbered starting from 0.

[Important]Important

The argRecord may have any of the following forms:

  • $<port number>.*

    E.g. $in.0.*

  • $<metadata name>.*

    E.g. $customers.*

  • <record variable name>[.*]

    E.g. Customers or Customers.* (both cases, if Customers was declared as record in CTL.)

  • lookup(<lookup table name>).get(<key value>)[.*]

    E.g. lookup(Comp).get("JohnSmith") or lookup(Comp).get("JohnSmith").*

  • lookup(<lookup table name>).next()[.*]

    E.g. lookup(Comp).next() or lookup(Comp).next().*

If a given record has a null reference, the function fails with an error.

Compatibility

The getFieldName(record,integer) function is available since CloverETL 3.0.0.

Example 68.201. Usage of getFieldName

There is a record having fields field1 and field2.

The function getFieldName($in.0, 0) returns field1.

The function getFieldName($in.0, 15)fails with an error.


See also:  getFieldIndex, getFieldLabel, getFieldType

getFieldProperties

map[string,string] getFieldProperties(record argRecord, integer index);

map[string,string] getFieldProperties(record argRecord, string fieldName);

The getFieldProperties() function returns an unmodifiable map of selected properties of the specified data field metadata. Fields are indexed starting from 0.

New properties may be added to the map in future versions.

If a null reference is passed to any of the arguments, if the field index is out of range or if the record does not contain a field with the specified name, the function fails with an error.

Compatibility

The getFieldProperties(re) function is available since CloverETL 4.1.0-M1.

Example 68.202. Usage of getFieldProperties

Assume there is a record with fields rawValue of type string and convertedValue of type integer on the first input and first output port.

map[string, string] properties = getFieldProperties($out.0, "convertedValue");
// converts $in.0.rawValue to an integer using format and locale from $out.0.convertedValue
$out.0.convertedValue = str2integer($in.0.rawValue, properties["format"], properties["locale"]);


See also:  getRecordProperties

getFieldType

string getFieldType(record argRecord, integer index);

The getFieldType() function returns the type of a field you specify by its index (i.e. field's number starting from 0). The returned string is the name of the type (string, integer, ...), see Data Types in Metadata. Example code:

string dataType = getFieldType($in.0, 2);

will return the data type of the third field for each incoming record (e.g. decimal).

[Important]Important

Records as arguments look like the records for the getFieldName() function. See above.

If a given record has a null reference, the function fails with an error.

Compatibility

The getFieldType(record,integer) function is available since CloverETL 3.0.0.

Example 68.203. Usage of getFieldType

There is a record having first field of data type string. The function getFieldType($in.0, 0) returns string.


See also:  getFieldIndex, getFieldLabel, getFieldName

getIntValue

integer getIntValue(record record, integer index);

integer getIntValue(record record, string field);

The getIntValue() function returns the value of an integer field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getIntValue(record,integer) and getIntValue(record,string) functions are available since CloverETL 3.2.0.

Example 68.204. Usage of getIntValue

There is a record having integer fields field1 and field2 with values 25 and 22.

The function getIntValue($in.0, 1) returns 22.

The function getIntValue($in.0, "field1") returns 25.


See also:  getBoolValue, getByteValue, getDateValue, getDecimalValue, getLongValue, getNumValue, getStringValue, getValueAsString, setIntValue

getLongValue

long getLongValue(record record, integer index);

long getLongValue(record record, string field);

The getLongValue() function returns the value of a long field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getLongValue(record,integer) and getLongValue(record,string) functions are available since CloverETL 3.2.0.

Example 68.205. Usage of getLongValue

There is a record having fields field1 and field2 with values 443L and 509L.

The function getLongValue($in.0, 1) returns 509.

The function getLongValue($in.0, "field1") returns 443.


See also:  getBoolValue, getByteValue, getDateValue, getDecimalValue, getIntValue, getNumValue, getStringValue, getValueAsString, setLongValue

getNumValue

number getNumValue(record record, integer index);

number getNumValue(record record, string field);

The getNumValue() function returns the value of a number field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getNumValue(recored,integer) and getNumValue(record,string) functions are available since CloverETL 3.2.0.

Example 68.206. Usage of getNumValue

There is a record having fields field1 and field2 with values 1.41 and 1.7.

The function getNumValue($in.0, 0) returns 1.41.

The function getNumValue($in.0, "field2") returns 1.7.


See also:  getBoolValue, getByteValue, getDateValue, getDecimalValue, getIntValue, getLongValue, getStringValue, getValueAsString, setNumValue

getRecordProperties

map[string,string] getRecordProperties(record argRecord);

The getRecordProperties() function returns an unmodifiable map of selected properties of the specified record metadata.

New properties may be added to the map in future versions.

If a null reference is passed as the argument, the function fails with an error.

Compatibility

The getRecordProperties(record) function is available since CloverETL 4.1.0-M1.

Example 68.207. Usage of getRecordProperties

Assume there is a record with fields rawValue of type string on the first input and first output port.

map[string, string] properties = getRecordProperties($out.0);
// converts $in.0.rawValue to a date using locale and time zone from $out.0
date convertedValue = str2date($in.0.rawValue, properties["locale"], properties["timeZone"]);


See also:  getFieldProperties

getStringValue

string getStringValue(record record, integer index);

string getStringValue(record record, string field);

The getStringValue() function returns the value of a string field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The getStringValue(record, integer) function is available since CloverETL 3.2.0.

Example 68.208. Usage of getStringValue

There is a record having fields field1 and field2 with values orange and yellow.

The function getStringValue($in.0, 0) returns orange.

The function getStringValue($in.0, "field2") returns yellow.


See also:  getBoolValue, getByteValue, getDateValue, getDecimalValue, getIntValue, getLongValue, getNumValue, getValueAsString, setStringValue

getValueAsString

string getValueAsString(record record, integer index);

string getValueAsString(record record, string field);

The getValueAsString() function returns the value of a field (no matter its type) as a common string. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error.

Compatibility

The getValueAsString(record,integer) and getValueAsString(record,string) function is available since CloverETL 3.2.0.

Example 68.209. Usage of getValueAsString

There is a record having fields field1 and field2 of boolean data type with values true and false.

The function getValueAsString($in.0, 0) returns true as string.

The function getValueAsString($in.0, "field2") returns false as string.


See also:  getBoolValue, getByteValue, getDateValue, getDecimalValue, getIntValue, getLongValue, getNumValue, getStringValue

isNull

boolean isNull(record record, integer index);

boolean isNull(record record, string field);

The isNull() function checks whether a given field is null. The field is identified by its index (integer) or name (string).

Compatibility

The isNull(record,integer) and isNull(record,string) function is available since CloverETL 3.2.0.

Example 68.210. Usage of isNull

There is a record having fields field1, field2, field3 and field4 with values true, false, null and null, respectively.

The function isNull($in.0, 0) returns false.

The function isNull($in.0, 2) returns true.

The function isNull($in.0, "field2") returns false.

The function isNull($in.0, "field4") returns true.


See also:  isEmpty, isnull

length

integer length( );

The length() function returns the number of fields of a record the function is called on.

For a record with null reference, the function returns 0.

Compatibility

The length(record) function is available since CloverETL 3.0.0.

Example 68.211. Usage of length

There is an input record having 14 fields. The function length($in.0) returns 14.


See also:  String functions: length, Container functions: length

resetRecord

void resetRecord(record record);

The function resetRecord() resets fields of the record to default values.

Compatibility

The resetRecord(record) function is available since CloverETL 3.2.2 or earlier.

Example 68.212. Usage of resetRecord

The output record in the example will contain field field3 set to 3. The field field2 will contain null, as the field is reset to the default value.

$out.0.field2 = 2;
resetRecord($out.0);
$out.0.field3 = 3;


See also:  length

setBoolValue

voidsetBoolValue(record record, integer index, boolean value);

voidsetBoolValue(record record, string field, boolean value);

The setBoolValue() function sets a boolean value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of the record has a different data type, the function fails with an error.

Compatibility

The setBoolValue(record,integer,boolean) and setBoolValue(record,string,boolean) functions are available since CloverETL 3.2.0.

Example 68.213. Usage of setBoolValue

There is a record of booleans having fields field1 and field2.

The function setBoolValue($out.0, 0, true) sets the first field of an output record to true.

The function setBoolValue($out.0, "field2", false) sets field field2 of an output record to false.

The function setBoolValue($out.0, "field3456") fails with an error. The field field3456 does not exist.


See also:  getBoolValue, setByteValue, setDateValue, setDecimalValue, setIntValue, setLongValue, setNumValue, setStringValue

setByteValue

voidsetByteValue(record record, integer index, byte value);

voidsetByteValue(record record, string field, byte value);

The setByteValue() function sets a byte value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The setByteValue(record,integer,byte) setByteValue(record,string,byte) functions are available since CloverETL 3.2.0.

Example 68.214. Usage of setByteValue

There is a record of booleans having fields field1 and field2.

The function setByteValue($out.0, 0, str2byte("etc", "utf-8")) sets the first field to byte value of string etc (0x65, 0x74, 0x63).

The function setByteValue($out.0, "field2", str2byte("opt")) sets the second field to byte value of opt (0x6f, 0x70, 0x74).


See also:  getByteValue, hex2byte, setBoolValue, setDateValue, setDecimalValue, setIntValue, setLongValue, setNumValue, setStringValue, str2byte

setDateValue

voidsetDateValue(record record, integer index, date value);

voidsetDateValue(record record, string field, date value);

The setDateValue() function sets a date value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The setDateValue(record,integer,date) and setDateValue(record,string,date) functions are available since CloverETL 3.2.0.

Example 68.215. Usage of setDateValue

The function setDateValue($out.0, 0, '2010-10-10') sets the first field of an output record to 2010-10-10.

the function setDateValue($out.0, "field", '2011-11-11')


See also:  getDateValue, setBoolValue, setByteValue, setDecimalValue, setIntValue, setLongValue, setNumValue, setStringValue

setDecimalValue

void setDecimalValue(record record, integer index, decimal value);

void setDecimalValue(record record, string field, decimal value);

The setDecimalValue() function sets a decimal value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of a record has a different data type, the function fails with an error.

Compatibility

The setDecimalValue(record,integer,decimal) and setDecimalValue(record,string,decimal) functions are available since CloverETL 3.2.0.

Example 68.216. Usage of seDecimalValue

The function setDecimalValue($out.0, 0, 3.14D) sets the first field of an output record to 3.14.

The function setDecimalValue($out.0, "field3", 2.72D) sets the first field of an output record to 2.72D


See also:  getDecimalValue, setBoolValue, setByteValue, setDateValue, setIntValue, setLongValue, setNumValue, setStringValue

setIntValue

void setIntValue(record record, integer index, integer value);

void setIntValue(record record, string field, integer value);

The setIntValue() function sets an integer value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of a record has a different data type, the function fails with an error.

Compatibility

The setIntValue(record,integer,integer) and setIntValue(record,string,integer) functions are available since CloverETL 3.2.0.

Example 68.217. Usage of setIntValue

The function setIntValue($out.0, 1, 2718) sets the second field of an output record to 2718.

The function setIntValue($out.0, "field1", 1414) sets the field field1 of an output record to 1414.


See also:  getIntValue, setBoolValue, setByteValue, setDateValue, setDecimalValue, setLongValue, setNumValue, setStringValue

setLongValue

void setLongValue(record record, integer index, long value);

void setLongValue(record record, string field, long value);

The setLongValue() function sets a long value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of record has a different data type, the function fails with an error.

Compatibility

The setLongValue(record,integer,long) and setLongValue(record,string,long) functions are available since CloverETL 3.2.0.

Example 68.218. Usage of setLongValue

The function setLongValue($out.0, 0, 8080L) sets the first field of a record to 8080.

The function setLongValue($out.0, "field3", 127L) sets the field field3 of an output record to 127.


See also:  getLongValue, setBoolValue, setByteValue, setDateValue, setDecimalValue, setIntValue, setNumValue, setStringValue

setNumValue

void setNumValue(record record, integer index, number value);

void setNumValue(record record, string field, number value);

The setNumValue() function sets a number value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of a record has a different data type, the function fails with an error.

Compatibility

The setNumValue(record,integer,number) and setNumValue(record,string,number) functions are available since CloverETL 3.2.0.

Example 68.219. Usage of setNumValue

The function setNumValue($out.0, 2, 2.718) sets the third field of an output record to 2.718.

The function setNumValue($out.0, "field1", 1.732) sets the field field3 of an output record to 1.732.


See also:  getNumValue, setBoolValue, setByteValue, setDateValue, setDecimalValue, setIntValue, setLongValue, setStringValue

setStringValue

void setStringValue(record record, integer index, string value);

void setStringValue(record record, string field, string value);

The setStringValue() function sets a string value to a field. The field is identified by its index (integer) or name (string).

If a given record has a null reference, the function fails with an error. If the accessed field of a record has a different data type, the function fails with an error.

Compatibility

The setStringValue(record,integer,string) and setStringValue(record,string,string) functions are available since CloverETL 3.2.0.

Example 68.220. Usage of setStringValue

The function setStringValue($out.0, 1, "chocolate cake") sets the second field of an output record to chocolate cake.

The function setStringValue($out.0, "field1", "donut") sets the second field donut of an output record to donut.


See also:  getStringValue, setBoolValue, setByteValue, setDateValue, setDecimalValue, setIntValue, setLongValue, setNumValue