Data types

Every value in EFX has one of six data types: text, number, indicator, date, time or duration. An expression gives either a single value (scalar) or a sequence of values of one data type. A field takes its data type from its type in the SDK. Context variables are different: they hold a place in the notice, not a value. This page describes each data type, sequences, the type context, and the data type that each SDK field type gives.

You write the type names text, number, indicator, date, time and duration only where you declare something, such as a variable number:$total. A star after the name, as in text*, declares a sequence. Everywhere else, the translator finds the type itself (see Type checking).

Text

The data type text holds a string of characters, such as a name, a description, a code or an identifier.

You write a text in single or double quotes, as in 'Lot 1' (see Text literal). Fields of the SDK types text, text-multilingual, code, internal-code, id, id-ref, url, email and phone have text values. When EFX reads a text from a field, it removes the spaces at its start and end, and replaces each run of spaces, tabs or line breaks inside it with a single space.

A field of type text-multilingual holds one text for each language of the notice, so a reference to it gives a sequence. To select one text, use a predicate on the language attribute languageID or, in templates, the property :preferredLanguageText (see Field property).

A text is never treated as another type: BT-00-Text == 42 is an error. To compare a text with a number, convert one of the two (see Type conversion).

Examples

WITH ND-Root COMPUTE BT-00-Code == BT-00-Text

A code field and a text field both have text values.

WITH ND-Root COMPUTE count(BT-00-Text-Multilingual[BT-00-Text-Multilingual/@languageID == 'FRA']) > 0

True when the multilingual field has a French text.

The documentation of EFX-1 called this type "string". In EFX-1, a reference to a multilingual field gave the text in the preferred language, as a single value. In EFX-2, it gives the texts in all languages, as a sequence. So if you compare such a field with a single value, select one language first.

See also: Text functions

Number

The data type number holds a numeric value, whole or decimal.

You write numbers without quotes: 42, -3.5, .5 (see Number literal). EFX does not distinguish between whole and decimal numbers: 10 / 4 is 2.5. Fields of the SDK types number, integer, amount and measure have number values. The currency of an amount and the unit of a measure are not part of the number: they are attributes of the field (see Attribute).

Examples

WITH ND-Root COMPUTE BT-00-Amount + BT-00-Integer

An amount and an integer are both numbers.

WITH ND-Root COMPUTE sum(BT-13-Number)

Indicator

The data type indicator holds one of two values: true or false.

You write indicators TRUE and FALSE, or ALWAYS and NEVER (see Indicator literal). Fields of the SDK type indicator have indicator values, and every condition gives one: a comparison, is present, in, like, and their combinations with and, or and not. Predicates, if … then … else, WHEN clauses and the ASSERT and REPORT clauses of rules all expect an indicator.

An indicator is not a text: you compare it with TRUE or FALSE, not with 'true'.

Examples

WITH ND-Root COMPUTE BT-00-Number > 0 and BT-00-Indicator

An indicator field used directly as a condition.

WITH ND-Root COMPUTE count(BT-13-Text[BT-13-Indicator == FALSE])
The documentation of EFX-1 called this type "boolean".

Date

The data type date holds a calendar date with a time zone, without a time of day.

You write dates without quotes: 2024-03-01Z, 2024-03-01+01:00 (see Date literal). Fields of the SDK types date and zoned-date have date values. eForms keeps dates and times in separate fields, so EFX has no type that combines the two.

You compare dates with the comparison operators. The difference between two dates is a duration, and a date plus or minus a duration is another date (see Date and duration arithmetic).

Examples

WITH ND-Root COMPUTE BT-00-StartDate + P1M <= BT-00-EndDate

True when the end date is at least one month after the start date.

WITH ND-Root COMPUTE BT-00-EndDate - BT-00-StartDate

The duration between two dates.

Time

The data type time holds a time of day with a time zone, without a date.

You write times without quotes: 09:00:00Z, 17:30:00+01:00 (see Time literal). Fields of the SDK types time and zoned-time have time values. You compare times with the comparison operators.

Examples

WITH ND-Root COMPUTE BT-00-StartTime >= 09:00:00+01:00

Duration

The data type duration holds a length of time, in days, weeks, months or years.

You write durations without quotes: P10D (ten days), P2W (two weeks), P6M (six months), P1Y (one year) (see Duration literal). A field of the SDK type duration stores a number, and a unit in its attribute unitCode: DAY, WEEK, MONTH or YEAR. EFX reads the two together as one duration.

There are two kinds of duration. Days and weeks have a fixed length: a week is seven days. Months and years do not, because months differ in length. To compare a duration in months or years with one in days or weeks, EFX adds both to the current date and compares the two dates. So the result of such a comparison can depend on the day on which the expression is read.

You can add and subtract durations, multiply them by a number, compare them, and add them to a date or subtract them from it (see Date and duration arithmetic).

Examples

WITH ND-Root COMPUTE BT-00-Duration > P6M
WITH ND-Root COMPUTE BT-00-EndDate - BT-00-StartDate <= P30D
In EFX-1, this type was called measure, and the functions add-duration and subtract-duration were called add-measure and subtract-measure.

Sequence

A sequence is an ordered series of zero or more values of the same data type.

Syntax
<type>*
<type>

one of the data types text, number, indicator, date, time and duration. With a star after it, it is the type of a sequence of such values, for example in a declaration: text*:$names.

A value that is not a sequence is called a single value, or scalar.

Sequences come from:

  • references to fields that can give more than one value from their context (see Repeatability);

  • values written in square brackets, such as [1, 2, 3] (see Sequence construction);

  • iterations, for … return, and codelist references, such as [...authority-activity];

  • functions such as distinct-values and split, and variables and functions declared with a sequence type.

A sequence never contains another sequence. It can contain the same value more than once, and it can be empty. The values of a field come in the order in which they occur in the notice.

You test sequences with in, is empty, has duplicates, every and some, summarise them with functions such as count and sum, and take their values one at a time with for … return. To select one value by its position, use an index, such as [at 1] (see Index).

You can always use a single value where a sequence is expected, whatever it is: a literal, a field reference, a variable or the result of a calculation. It is then a sequence of one value, so count('x') is 1. A field that is not in the notice gives an empty sequence. The reverse is not true: where a single value is required, for example as an operand of == or +, a sequence is never accepted, even when it contains only one value.

Examples

WITH ND-Root COMPUTE 'x' in BT-13-Text
WITH ND-Root COMPUTE count(BT-00-Text)

BT-00-Text gives a single value, which count accepts as a sequence of at most one value.

LET text*:$names = BT-13-Text;
DISPLAY ${count($names)};

A template file with a sequence variable.

EFX-1 wrote sequences in parentheses, ('a', 'b'), and had no sequence types for variables and parameters.

See also: Sequence functions

Context (variable type)

The type context is the type of the variables that hold a place in the notice, one occurrence of a field or a node, instead of a value.

Syntax
context:$<name> in <field-or-node-reference>
context:$<name> = <field-or-node-reference>
<name>

the name of the variable.

<field-or-node-reference>

a reference to a field or a node. The variable takes each of its occurrences in turn.

You declare a context variable in two places. In an iteration or a quantified expression, with in, it takes each occurrence in turn: for context:$node in ND-RepeatableNode return …. In the context declaration of a template line or a rule-set, with =, it gives a name to that context: WITH context:$node = ND-RepeatableNode (see Context variable).

You then use the variable with ::, to read a field from the place that it holds: $node::BT-21-Number. A context variable that holds a field can also be used as a value: it gives the value of the field in that place. A context variable that holds a node has no value.

There is no sequence of contexts (context*), and you cannot use context as the type of a parameter, a function or a variable declared with LET.

Examples

WITH ND-Root COMPUTE every context:$value in BT-23-Number satisfies $value > 0

A context variable that holds a field, used as a value.

WITH context:$node = ND-RepeatableNode DISPLAY Node;
    WITH ND-RepeatableInRepeatableNode DISPLAY ${$node::BT-21-Number};

In a template file, the nested line reads a field of the context of its parent.

In EFX-1, you could declare context variables in iterations only.

See also: Context override

Field types and their EFX data types

The table gives the EFX data type of each SDK field type.

SDK field type EFX data type Notes

text

text

text-multilingual

text

One text for each language: a reference gives a sequence.

code, internal-code

text

A code of the codelist of the field.

id, id-ref, url, email, phone

text

number, integer

number

amount

number

The currency is in the attribute currencyID.

measure

number

The unit is in the attribute unitCode.

indicator

indicator

date, zoned-date

date

time, zoned-time

time

duration

duration

A number and a unit (DAY, WEEK, MONTH or YEAR), read together as one duration.

The SDK defines the field types in its metadata (fields/fwd/data-types.json). You can combine fields whose types give the same EFX data type: you can add an amount to an integer, and compare a code with a text.

Examples

WITH ND-Root COMPUTE BT-00-Url == BT-00-Email

Two text values.

WITH ND-Root COMPUTE BT-00-StartDate == BT-00-Zoned-Date

A date field and a zoned-date field are both dates.

In SDK 1, durations had the field type measure, which EFX-1 read as a duration. In SDK 2, durations have the field type duration, and measure is a number.

See also: Type checking