Creating Data for a Child Class From Another Data Class Using an Operation

This document provides information on how to use an operation to create data for a child data class from a different data class (not necessarily its parent class).

The process described below demonstrates how to add data to the child class (MYCLASS1.CL1) of a data class (MYCLASS1) from a different data class (MYCLASS2). This is done by adding a script that will create an operation on (MYCLASS1), called from (MYCLASS2):

  1. Open your data class (MYCLASS1).
  2. In the Methods block of th Methods tab:
    1. Enter a new method code (MYMETH1) in the Code field.
    2. Enter a description for the method in the Description field.
    3. Select an appropriate return type in the Return type field.
    4. Select the Operation check box. It will automatically generate the keys in the Keys block.
  3. In the Parameter definitions block, enter parameters (MYPARAM1) that need to be passed.
  4. In the Scripts block of the General tab:
    1. Select the appropriate type for your script in the Type field.
    2. Accept the default code displayed in the Scripts field. It is automatically generated using the class code and the script type. You can also manually enter a unique code for your script.
    3. Accept the numeric value displayed in the Running order field. It is automatically generated to control the order in which the "$PROPERTIES" and "$METHODS" labels are called in the event. You can also manually enter the running order code for your script.
  5. Click the Actions button of your script, and click Processing editor. Enter the source code below.
    Note: This example uses the key passed in the Keys block of the Methods tab to read the current context from "MYCLASS1", and then update the property (PROP1) using parameter "MYPARAM1" which is passed to it.
    $Structure MYCLASS1###########################################METHODS ###########################################$METHODSCase CURPTHWhen ""Case ACTIONWhen "MYMETHOD" Gosub MYMETHOD # Update MYPROP1 method Endcase EndcaseReturn# Update MYPROP1 using MYPRAM1 which is passed# KEY1 and MYPARAM1 are passed and used in this operation$MYMETHODLocal Integer NEWLINE# Use standard method CRUD to read MYCLASS1ASTATUS=fmet this.AREAD(MYCLASS1)If ASTATUS<>[V]CST_AOKARET_VALUE= CST_AFALSEReturnElseARET_VALUE= CST_ATRUE# create a new line for MYCLASS1.CL1 at last positionNEWLINE=fmet this.ADDLINE("CL1",[V]CST_ALASTPOS)If NEWLINE=[V]CST_ANOTDEFINED # check status after creating lineARET_VALUE = CST_AFALSEEndifIf ARET_VALUE = CST_ATRUE# update CL1 with values passed this.CL1(NEWLINE).MYPROP1 = MYPARAM1ASTATUS=fmet this.AUPDATEIf ASTATUS<>[V]CST_AOKARET_VALUE= CST_AFALSEEndifEndifEndifReturn
  6. Once the operation has been created, call it from data class "MYCLASS2", or from any other data class.
    Enter code similar to the following. It calls "MYMETHOD" which was defined above.
    ############################################### Data Class - MYCLASS2 ##############################################################################################METHODS ###############################################$METHODSCase CURPROWhen ""Case ACTIONWhen "AINSERT_AFTER" : Gosub AINSERT_AFTEREndcaseEndcaseReturn# Action After insert$AINSERT_AFTER# Declaration new instance of MYCLASS2 data classLocal Instance MYCLASS Using C_MYCLASS2MYCLASS = NewInstance C_MYCLASS2 AllocGroup NullASTATUS=fmet MYCLASS.MYMETHOD(KEYID,MYPARM1)If ASTATUS<>[V]CST_ATRUEASTATUS = fmet THIS.ASETERROR ("", "Not updated.", [V]CST_AERROR) Endif# Free instancesFreeGroup MYCLASSReturn
  7. Save your script.
  8. Save and validate your data class.