How to set an initial value for a property field
This ‘How-to’ provides information on how to set an initial value for a property (field). The default value of a property is ‘blank’ (no value).
The following development process demonstrates how to add a simple script to a Data class to set the initial value of a property (MYPROP1) to today’s date:
-
Open your Data class.
-
Select the General tab > Scripts block and set the following field values:
Type: Select a type appropriate for your script.
Scripts Leave the default code displayed. This is automatically generated using the class code and script type. Alternatively, enter a unique code for your script.
Running order:. Leave the numeric displayed. This is automatically generated to control the order in which the '$PROPERTIES' and '$METHODS' labels are called in the event. Alternatively, enter the running order code for your script.
-
To add your script, right-click the Scripts code and select Processing editor from the selection menu. Enter the following code:
# Properties for MYCLASS
$PROPERTIES
Case CURPRO
When "MYPROP1" : Gosub MYPROP1
Endcase
Return
# Action to be carried out by MYPROP1
$MYPROP1
Case ACTION
# Set default date as today
When "INIT"
this.MYPROP1 = date$
Endcase
Return
- Note that in the above example code:
- The property ‘INIT’ will only be executed in ‘Create’ mode. It will not be executed in ‘Modify’ mode.
- Although this example will set the default value for the property 'MYPROP1' to today’s date, the principle and format can be used for any property (field) type.
4. Save your script.
5. Save and validate your Data class.