BAM code specifics

Some code practice that is specific to BAM.

Next field instructions

In a function where you need to set the focus to a specific field, you can not use a NEXT FIELD instruction. The NEXT FIELD statement only works in the scope of a dialog that is not referenced in a function.

Instead you need to make a call to the nextField() method of the ui.DIALOG class. This method allows you to set the focus to a specified field. However, unlike NEXT FIELD, the nextField() method will not skip subsequent instructions so therefore you must return a status in the dialog control instruction that skips other statements.

In a code event that manages a dialog, this can be coded as shown:
CALL dlg.nextField("field_01")
LET dlgCtrlInstruction = libdbappEvents.CONTINUE_DIALOG

For more information on using the nextField() method, see the ui.Dialog.nextField page in Genero Business Development Language User Guide. For examples of use, see dlgEvent_After_EditDialog, dlgEvent_Before_SearchDialog, or dlgEvent_record_AfterInput.

Cancel Insert instruction

In the function for the Before Insert Row event, the CANCEL INSERT instruction may need to be invoked, if for example the user is not allowed to insert rows. As CANCEL INSERT can only be used inside BEFORE INSERT statement, you must use the dlgCtrlInstruction to return the cancel insert to the BAM. In the trigger, the code will look as follows:
LET dlgCtrlInstruction = libdbappEvents.CANCEL_INSERT

In this code event, you can cancel the insertion regardless of the invoked mode (uiMode). The user is returned to the same state before the event was triggered. For instance, if the user is in DISPLAY mode, and they click New (or Append in a detail of a master-detail) to insert a row, in the code event the CANCEL_INSERT prevents the change to add mode (C_MODE_ADD).