Business Rule: Before BR Type Use Case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2025 01:06 AM
1.0 Business Rule:
- Server-side script
- Runs when record is displayed, inserted, updated, or deleted or table is queried.
- Table for business rules – sys_script.
- Types of business rule: Before, after, Async and Display.
- Two steps of business rule: when to run: the time when BR is configured for the record being modified or accessed and action.
- The Type of database operation: insert, update, query and delete.
- Global variables in business rules:
- Current: current now this is something which basically store state of the same record you are working on.
- Previous: Basically, captures the previous state of the record you are working on before any update or delete.
- G_scratchpad: object is available on display type of business. If you want field value from database server end on a client that time, use g_scratchpad.
- Glidesystem:
- Actions Performed by business rule:
- Update the field value after creating the record as per the values of other fields.
- Stop users updating or inserting records if invalid data is used.
- Display information message when record is inserted.
- Create child tasks when parent is created.
1.1 Before: Before BR is triggered when user submits the form however before any action is taken on the record in the database.
- Major use case of Before BR.
- Abort update of record if form does not have expected value.
- Populate assignment group before creation of incident record.
- Users should not delete a record creation of incident record.
- Users should not delete a record if the condition does not match.
- The date should be updated before inserting a record.
- Without script scenario:
- Scenario(insert): User should not be able to create new incident if category is inquiry/help and assignment group is not service desk.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table (Incident) and active and advanced true.
- When to Run
- Actions
- Scenario (update): Change the state of incident to in progress when user updates work notes.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table (Incident) and active and advanced true.
- When to Run
- Actions
Note: when form save and adding work notes immediately state changes to in progress.
- Scenario (delete): If State is new then user should not be able to delete the incident.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table (Incident) and active and advanced true.
- When to Run
- Actions
- With Script Scenario:
- Scenario (Insert): User should not be able to create new incident if there is an existing incident with same short description and with same caller.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table (Incident) and active and advanced true.
- When to Run
- Actions
- Advanced:
// This function checks if there is an existing incident record with the same short description and caller ID
function executeRule(current, previous /*null when async*/) {
// Create a new GlideRecord object for the 'incident' table
var gr = new GlideRecord('incident');
// Add a query condition to filter incidents by the current short description
gr.addQuery('short_description', current.short_description);
// Add another query condition to filter incidents by the current caller ID
gr.addQuery('caller_id', current.caller_id);
// Execute the query to retrieve matching incident records
gr.query();
// If there is at least one matching incident record
if (gr.next()) {
// Set the abort action flag to prevent creating a new record
current.setAbortAction(true);
// Add an error message indicating that a new record cannot be created because an existing one already exists
gs.addErrorMessage("You cannot create a new record as you already have an existing one.");
}
}
// Call the executeRule function with the current and previous parameters
executeRule(current, previous);
- Scenario (update): User should not be able to change the state of story to work in progress if there is no scrum task created in the story.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table () and active and advanced true.
- When to Run
- Actions
- Advanced:
- Scenario (Delete): Configuration item cannot be deleted if there are tasks or incidents associated with same CI.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table (Incident) and active and advanced true.
- When to Run
- Actions
- Advanced:
Note: Go to My work> task > List view> delete any CI That have task attached and verify.
- Scenario (Query): Only operation CI Should be queried if user is not admin.
Steps:
- Navigate to All>Business Rule > Create New
- Fill all required fields like Name, table (Incident) and active and advanced true.
- When to Run
- Actions
- Advanced:
Note: When user has admin role
Note: When user not admin role
Please mark this response as correct or helpful if it assisted you with your question.