Business Rules

Prev Next

During the design of a WebApp, you can currently incorporate business rules into a specific field triggering an action or event.

You can register Business Rules that are triggered by a button click, a checkbox selection, a toggle switch change, or change to a specific field value.

For example, business rules can be created on the Customers page to force a customer’s name to display in all upper case letters, or to default Date Shipped to be the same as Order Date. A page Designer can add a button with a business rule that, when clicked, runs the rule that adds one day to the Date Shipped date.

Business Rule Guidelines

  • Business Rules are stored procedures which are generally created from a select view.

    Note

    When writing a business rule, you should write the procedure so that it can be repeatably run. Rerunning an event should have a predictable and repeatable result.  So if you have a procedure that creates child records or updates a field, it should be written in a way where, if the event get rerun, it does not create more records or apply the same update again. The procedure should evaluate the current state of the record to determine if is has already been run.

    For example, use a LEFT OUTER JOIN for inserting new records on the target table and only insert records that do not already exist in the target.

  • Common naming for stored procedures is webTable_Event_Description#Action where:

    • Table - Table registered to the page that calls the business rule

    • Event - Event that calls the business rule

    • Description - Procedure description or field being modified

    • # - An optional number to prevent duplication

    • Action - Action performed by stored procedure: 'Upd' if update; 'Ins' if insert; 'Del' if delete

  • Name stored procedures that include a select query view the same as the select view, without the 'Sel' suffix.

    Governance Example

    Migration Example

    Select View

    webRequestMasterRecipeStepsOperations_BeforeDelete_OpPhasesDelSel

    webTargetSourceReportUpdSel

    Stored Procedure

    webRequestMasterRecipeStepsOperations_BeforeDelete_OpPhasesDel

    webTargetSourceReportUpd

    Select View

    webRequestPurchasingContractItems_OnValidate_PSTYP_3UpdSel

    webTargetSourceRuleInsSel

    Stored Procedure

    webRequestPurchasingContractItems_OnValidate_PSTYP_3Upd

    webTargetSourceRuleIns

  • Determine under which validation conditions the business rule should execute. By default, business rules runs after Validation rules, which means they execute if the record is left in a valid state after the Validation Rule"s execution. However, there may be conditions where a business rule should ALWAYS execute. For example, a counter on how many times a button has been clicked is generally unconcerned with record validity. Alternatively, you may want to run an event even if the validation fails to record information or update a parent record.

  • Business rules should NEVER throw Internal Errors. Validation rules exist to ensure that the expected configuration for success exists prior to executing. Any runtime failures that may occur (in other words, database connection failures) should be Try/Catch formatted typed Messages back to the user.

Register a Stored Procedure Business Rule as Part of an Event

Note

The Buiness Rule view or stored procedure must already exist in the database (configured as the datastore used by the WebApp) and can be registered as a Dataset in the Catalog module.

  1. On the Construct Preview’s home page, edit the required WebApp. The WebApp configuration page is displayed.

  2. Access Pages > Your Page > Grid or Form > Events in the Tree Navigation panel.

  3. If you want to create a new event, click Add Event. Refer to Register an Event for more information.

  4. Click an existing event child node and click More Options (…) > Add Business Rule Stored Procedure Task. The Details Pane is updated with the Business Rule Stored Procedure fields.

  5. Enter the fields/properties listed in the following table as required using either form-based UI or Advanced mode:

    Note

    Enter the required Parameter Names and Dependent Tasks. Dependent Tasks can include different construct event tasks, either those configured in the same WebApp or those from different datasets.

    Property (Name: Type)

    Description

    Supported Values/Notes

    name: string
    required

    Name of the SQL stored procedure for business logic

    Enter the name of the business stored procedure. maxLength: 128 

    parameter_names: array of strings
    required

    List of field names that the stored procedure expects

    Enter the field names. The field name in the view should match the field names in the data grid. maxLength: 128

    dependent_tasks: array of strings

    A list of task names that must be completed before running this task

    Enter the name of dependent tasks. maxLength: 128

  6. Click Save.

Related Articles