How to disable or make a property editable from an update to a different property

This ‘How-to’ provides information on how to use business logic to disable a property (field), or make a property editable when the value in a different property is updated.

The following development process demonstrates how to add a simple script to a representation class to set the value of one property (MYPROP2) to "disabled" or "editable" as appropriate when the value in a different property (MYPROP1) is set.

  1. Open your representation class.

  2. Select the General tab >Scripts block, and set the following field values:

    Type: Select a type appropriate 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.

  3. To add your script, right-click the Scripts code and select Processing editor from the selection menu. Enter the following code:

$PROPERTIESCase CURPROWhen "MYCLASS.MYPROP1" : Gosub MYPROP1EndcaseReturn# Actions for "MYPROP1"$MYPROP1Case ACTIONWhen "PROPAGATE" : Gosub PROP1_PROPAGATEEndcaseReturn# Set MYPROP2 to Disabled or editable, depending on value of MYPROP1$PROP1_PROPAGATEIf THIS.MYPROP1 = CST_AYESASTATUS = fmet THIS.ASETATTRIBUTE("MYPROP2","$isDisabled","true")ElseASTATUS = fmet THIS.ASETATTRIBUTE("MYPROP2","$isDisabled","false")EndifReturn
  4.  Save your script.

  5.  Save and validate your representation class.