How to make a property mandatory or optional from an update to a different property
This ‘How-to’ provides information on how to use business logic to make a property (field) mandatory or optional when the value in a different property is updated.
The following development process demonstrates how to add a simple script to a data class to set the value of one property (MYPROP2) to mandatory or optional as appropriate, when the value in a different property (MYPROP1) is set.
Open your data class.
Select the General tab > Scripts block, and set the following field values:
Type: Select an appropriate type for your script.
Scripts: Accept 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: Accept the displayed numeric value. 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
Case CURPRO
When "MYPROP1" : Gosub MYPROP1
Endcase
Return
# Actions for "MYPROP1"
$MYPROP1
Case ACTION
When "PROPAGATE" : Gosub MYPROP1_PROPAGATE
Endcase
Return
# Set MYPROP2 to Mandatory or not, depending on value of MYPROP1
$MYPROP1_PROPAGATE
If THIS.MYPROP1 = CST_AYES
ASTATUS = fmet THIS.ASETATTRIBUTE("MYPROP2","$isMandatory","true")
Else
ASTATUS = fmet THIS.ASETATTRIBUTE("MYPROP2","$isMandatory","false")
Endif
Return
4. Save your script.
5. Save and validate your data class.