Class: RecordModel

diffusion.datatypes.RecordV2. RecordModel


new RecordModel()

diffusion.datatypes.RecordV2 data model.

A read only model can be created from any diffusion.datatypes.RecordV2 object using the asModel method. The model then provides direct access to the fields within the data. Fields may be accessed either by explicitly specifying the record and field occurrence or by specifying a key of the form:

recordName(recordIndex).fieldName(fieldIndex)

Indexes start from 0 and if omitted then 0 is assumed. The record name may also be omitted, in which case the first record definition. This form of addressing is useful when there is only one record definition.

So valid keys would be:

Address(4).AddressLine(3) The 4th AddressLine occurrence within the 5th Address record
Address.Name The first (or only) Name field within the first (or only) Address record
AddressLine(1) The 2nd AddressLine field within the first (or only) record
Name The first (or only) Name field within the first (or only) record

The diffusion.datatypes.RecordV2.RecordModel#recordCount and diffusion.datatypes.RecordV2.RecordModel#fieldCount methods are useful for determining the actual number of occurrences of variable multiplicity items.

Since:
  • 6.0

Methods


asRecordV2()

Creates an immutable diffusion.datatypes.RecordV2 object generated from the model.

Returns:

a new immutable instance

Type
diffusion.datatypes.RecordV2

fieldCount(recordName, recordIndex, fieldName)

Returns the actual number of occurrences of a named field within a specified record.

For all but variable fields this simply returns the schema defined number of occurrences of the field.

Parameters:
Name Type Description
recordName String

the record name

recordIndex Number

the record index

fieldName String

the field name

Returns:

the actual number of occurrences of the field

Type
Number

get(recordName [, recordIndex], fieldName [, fieldIndex])

Get a field value.

This allows an item to be addressed using a key of the form recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in which case 0 is assumed.

Parameters:
Name Type Argument Default Description
recordName String

the name of the record

recordIndex Number <optional>
0

the index of the record

fieldName String

the name of the field

fieldIndex Number <optional>
0

the index of the field

Returns:

the field value

Type
String
Example
// Get field value with record & field names and indices
var value = model.get("record", 0, "field", 0);

recordCount(recordName)

Returns the actual number of occurrences of a named record.

If the record is not variable, this is the same as the defined number of occurrences in the schema

Parameters:
Name Type Description
recordName String

the record name

Returns:

the actual number of occurrences of the record

Type
Number