Tips for Writing Business Rules and Data Builder Code

Here are some tips for writing Business Rules and Data Builder code:

·       Data Session: Code snippets are executed within the data session of the object from which the Data Handler and Business Rules objects are instantiated (usually a form). That means the code can access the cursors open in the data session’s work areas.

·       Current Work Area Cursor: When the code is run the cursor open in the current work area is the cursor for which the code is being run. This is important in Business Rules code because the same code is run for each cursor and the code may need to identify the cursor for which the code is being run. For example, when the PreSave code is run the current record of the cursor open in the current work area is the record being saved. What this means is that the ALIAS() function can be used to identify the cursor for which the code is being run as follows:

DO CASE

   CASE ALIAS() == “<specific alias>”

   * PreSave code for specific alias

   CASE ALIAS() == “<specific alias>”

   * PreSave code for specific alias

ENDCASE

·       Determining Open Cursors: To determine if a specific cursor is open, the USED() function can be used as follows:

IF USED(“<specific alias>”)

   * Code for specific alias

ENDIF

·       Forms: The methods and properties of the form for which the Data Handler and Business Rules objects are instantiated can be run and referenced in the code.

·       For example, the RefreshForm method of the active form can be run as follows:

IF _SCREEN.oApp.GetActiveForm()

   _SCREEN.oApp.oActiveForm.RefreshForm()

ENDIF

·       For example, the ISA of the active form can be identified by referencing the form’s cInitialSelectedAlias property as follows:

IF _SCREEN.oApp.GetActiveForm()

  lcISA = _SCREEN.oApp.oActiveForm.cInitialSelectedAlias

ENDIF

·       For example, the name of the active form can be identified by referencing the form’s Name property as follows:

IF _SCREEN.oApp.GetActiveForm()

   lcFormName = _SCREEN.oApp.oActiveForm.Name

ENDIF

More:

Useful Data Handler Methods