How to change the properties of one data class from another data class using a standard method
This ‘How-to’ provides information on how to use a standard method to change the properties (fields) of one data class from a different data class.
Methods are similar to operations:
The following development process demonstrates how to add a simple script to a data class (MYCLASS2) to update the properties (MYPROP1) of a different data class (MYCLASS1).
Open your data class (MYCLASS2).
Select the Methods tab >Methods block, and set the following field values:
Code: Enter a new method code (MYMETH1).
Description: Enter a description for the method.
Return type: Select an appropriate return type.
Operation: Select this option (yes). This will automatically generate the keys ( Keys block).
Enter parameters (MYPARAM1), which need to be passed ( Parameter definitions block).
Select the General tab >Scripts block, and set the following field values:
Type: Select an appropriate type for your script.
Scripts: Accept the displayed default code. 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 source code (see below):
Note: This example will update the property (MYPROP1) in data class 'MYCLASS1' from the data class 'MYCLASS2'.
# Structure MYCLASS2###########################################METHODS ###########################################$METHODSCase CURPTHWhen ""Case ACTIONWhen "AINSERT_AFTER" Gosub AINSERT_AFTER # Update after insertEndcase EndcaseReturn# Update properties in MYCLASS1 using MYCLASS2$AINSERT_AFTER# Declaration new instance of MYCLASS1 data classLocal Instance MYCLASS Using C_MYCLASS1MYCLASS = NewInstance C_MYCLASS1 AllocGroup NullASTATUS=fmet MYCLASS.AREAD(this.KEY_VALUE)If ASTATUS<>[V]CST_AOKASTATUS = fmet THIS.ASETERROR ("", "Not updated.", [V]CST_AERROR) ARET_VALUE= CST_AFALSEElse# change property values and updateMYCLASS.MYPROP1 = this.MYPROP2ASTATUS=fmet MYCLASS.AUPDATEIf ASTATUS<>[V]CST_AOKASTATUS = fmet THIS.ASETERROR ("", "Not updated.", [V]CST_AERROR) ARET_VALUE= CST_AFALSEElseARET_VALUE= CST_ATRUEEndifEndif# Free instancesFreeGroup MYCLASSReturn
6. Save your script.7. Save and validate your data class.