This article will cover the syntax of the ‘declare’ regular script statement.
The declare statement is used to create field definitions. Field definitions are relationships between fields or functions and are used to generate derived fields.
Statement syntax
Definition_name:
Declare Field | Fields Definition Tagged [tag_list]
Parameters [parameter_list]
Fields [field_list]
Definition_name | This is the name of the definition. It must be followed with a ‘:’. This name will be used to call on the definition in the ‘derive’ statement. |
Tag_list | This is a comma separated list of tags that will be applied to the derived fields. Applying tags is optional. |
Parameter_list | This is a comma separated list of parameters. Parameters must take the form of name=value. Parameter values can be overridden each time the definition is used. Parameters are optional. |
Field_list | This is a comma separated list of fields to be generated. |
Example
This example creates field definitions that create a calendar when used with a date field.
DATES:
Load * inline [
dataDate
01/01/2022
01/02/2022
01/03/2022
];
CALENDAR_DEFINITIONS:
DECLARE FIELD DEFINITION TAGGED '$date'
Fields
Year($1) as Year Tagged ('$numeric'),
Month($1) as Month Tagged ('$numeric'),
Date($1) as Date Tagged ('$date'),
Week($1) as Week Tagged ('$numeric');
DERIVE FIELDS FROM FIELDS dataDate USING CALENDAR_DEFINITIONS;
See this article for the code to our ultimate derived calendar.
Result
The field ‘dataDate’ is loaded into the app in the table ‘DATES’. In addition, 4 fields are created as specified by the definition.