display business rule in servicenow

2279

A Business Rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried. We use business rules to achieve tasks such as create events for email notifications and script actions.

Display Business Rules in details -https://servicenowhelpdesk.com

We have 4 type of business rule but in this article we will only focus on before business rule.

    1. Before business rule
    2. After business rule
    3. Async business rule
    4. Display business rule

Lets begin to understand Display Business Rule In ServiceNow

What is Display Business Rule?

Display Business Rules run after the data is read from the database and before the form is presented back to the user. Display Business Rules execute when a user requests a record form.

Display rule basically runs in two cases, which are as follows:-

        1. Display business rule provide server side data to client side
        2. Display business rule is triggered whenever a user open / loads form.

Example of display business rule:

We need to update the number of views on a comment or post. So, for that Display BR is being used.

To have a better understanding of this concept let’s have a look at below mentioned scenarios.

Scenario 1 – We need to set certain values on incident form if the logged in user is member of a particular group.

To achieve this use case, we first need to create a Display BR and then call the same in our client script. Please refer to the below attached screenshots.

 

Here is the BR to fulfill our work at server side.

(function executeRule(current, previous /*null when async*/ ) {


    g_scratchpad.fac = (gs.getUser().isMemberOf("a56f4cbfdb252410b9450342f396191c"));
    
})(current, previous);

 

Now, moving onto the client-side scripting to see how this g_scratchpad is called, and our requirement is achieved.

function onLoad() {
    //Type appropriate comment here, and begin script below

    var a = g_form.getValue('number');

    
    if (g_scratchpad.fac == true) {

        var pro = g_scratchpad.property;
        var myArr = pro.split(",");
        var pointer = "0";
        for (var i = 0; i < myArr.length; i++) {
            g_form.removeOption('u_business_service', myArr[i]);
        }
        if (content != '') {
            //alert('script 2');
            g_form.setValue('u_business_service', '10’);
            g_form.setValue('category', '1');
            g_form.setValue('subcategory', '2');
        }
    }

 

Scenario 2- We need to populate the caller email id if incident has any attachment.

First, we will have the BR with the following script.

(function executeRule(current, previous /*null when async*/) {

                            g_scratchpad.hasAttachments = current.hasAttachments();

                       g_scratchpad.email=current.caller_id.email.getDisplayValue();          

})(current, previous);

 

Now, we will move towards our client script part.

function onLoad() {  

   var email=g_scratchpad.email;

if(g_scratchpad.hasAttachments){

alert("Caller Email name==="+email);

}

}

 

FAQ

What is async business rule in servicenow?

Async Business Rules run after records are inserted/modified/queried. Async and after works similar the only difference is async run asynchronously as Scheduled Jobs. Async BR are queued by the scheduler to run as soon as they can be fit in. This allows the current transaction to finish without waiting for the rule and give the control back to user to continue working.

What is before business rule in servicenow?

Before BR as name itself justify works Before a record is saved to the database. Business rules execute after form submission and before the record update in the database. It runs before the database operation, so no extra operations are required.

What is after business rule in servicenow?

After a record is saved to the database. Business Rules execute after form submission and after the record update in the database.

What is display business rule in servicenow?

Display Business Rules run after the data is read from the database and before the form is presented back to the user. Display Business Rules execute when a user requests a record form.

What is before query business rule in servicenow?

Other than the four above mentioned rules we have Before Query rule. It is a type of business rule in ServiceNow that we can use to limit that what all records users can access from a given table. In other words, we can also say that it is used for data segregation on an instance. To understand this more clearly see the scenario mentioned below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here