Business Rule

The Business Rule DocType in TechMaju allows developers to create server-side scripts that execute when specific database events occur, such as displaying, inserting, updating, or deleting a record, or when a table is queried. Business rules ensure that certain conditions are met or actions are performed automatically when these events take place.

Understanding the Business Rule DocType

Purpose: The Business Rule DocType is designed to automate server-side logic within the TechMaju platform. It allows developers to define scripts that run in response to specific database interactions, ensuring that data integrity and business logic are consistently enforced.

Function: Business Rules execute server-side logic based on defined conditions and events. These rules respond to database operations regardless of how the data is accessed—through forms, lists, web services, or data imports. Business Rules do not directly monitor forms or form fields but execute their logic when forms interact with the database, such as when a record is saved, updated, or submitted.

Role Required

  • TM Core Developer: Can create, write, and delete Business Rules.

Business Rule Fields

Field

Description

Name

The name of the Business Rule.

DocType

The DocType to which the rule will be applied.

Application

The application where the rule will be used.

Run Order

The order in which the rule will be executed.

Active

A checkbox to activate or deactivate the rule.

DocType Event

The database event that triggers the rule:

  • Before Insert

  • After Insert

  • Before Validate

  • Before Save

  • After Save

  • Before Submit

  • After Submit

  • Before Cancel

  • After Cancel

  • Before Delete

  • After Delete

  • Before Save (Submitted Document)

  • After Save (Submitted Document)

Add message

Option to add a message that will be displayed when the rule is triggered.

Abort action

Option to abort the action if certain conditions are met.

Set Field Values

Specify the field and its values that should be set when the rule is triggered.

Script (Python)

The Python code that will be executed when the rule is triggered.

Procedure

  1. Navigate to Develop > Business Rule.

  2. Adding a New Business Rule:

    • Click on '+ Add Business Rule' to open the creation form.

    • Fill in the required fields: Name, DocType, Application.

    • Set the Run Order to determine the execution sequence of the rule.

    • Check the 'Active' checkbox if you want the rule to be active immediately.

    • Select the appropriate 'DocType Event' that will trigger the rule (e.g., Before Insert, After Save).

    • Optionally, check 'Add message' to display a message when the rule is triggered.

    • Optionally, check 'Abort action' to abort the action if certain conditions are met.

    • Use the 'Set Field Values' section to specify any field values that should be set when the rule is triggered.

    • Enter the Python code in the 'Script (Python)' field for more complex logic.

  3. Configuring the Business Rule:

    • Adjust the conditions and script as needed to fit the specific requirements of the DocType and the rule behavior.

    • Use the 'Add Row' option to define multiple field values if necessary.

  4. Saving and Viewing the Business Rule:

    • Click on 'Apply' to save the Business Rule.

    • The rule will be executed according to the specified conditions and events.

Best Practices

  • Test the Business Rules in a development environment before applying them to production.

  • Use Business Rules to enforce data integrity and automate business logic consistently across the application.

  • Regularly update and review Business Rules to ensure they remain effective and compatible with new versions of the TechMaju platform.

  • Document the purpose and functionality of each Business Rule within the platform to aid future maintenance.


Discard
Save

On this page

Review Changes ← Back to Content
Message Status Space Raised By Last update on