Field level triggers

Sometimes we may need to write business logic based on the values updated in certain fields. In such cases we write the logic in field level trigger procedures. These procedures are added to the logical write triggers itself. To create the Field level trigger, select the table field and click on [f] icon as shown in image below where field level trigger for ‘Name’ field of table ‘Customer’ has been created.

Creating field level trigger
Figure: Creating field level trigger

The code snippet below shows the procedure stub generated by the create field trigger button for Name field of table Customer in file c/custlwrite.p :

procedure p-Name:
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/

def input parameter v-rowid as rowid no-undo.
def input parameter v-newvalue like Customer.Name no-undo.
def input parameter v-oldvalue like Customer.Name no-undo.
def output parameter v-xerrc like xerr.xerrc no-undo.

find Customer where rowid(Customer) = v-rowid exclusive-lock no-error.

message program-name(1) skip
''
view-as alert-box.

release Customer.

end procedure. /* p-Name */

The parameters in the above procedure are:

  • v-rowid- Row ID of the record being updated as input parameter
  • v-newvalue – New value being updated as input parameter
  • v-oldvalue – Previously stored value of the field as input parameter
  • v-xerrc – Error code returned by the procedure if any

results matching ""

    No results matching ""