servicenow business rule interview questions

What are Business Rules? What are the different type of Business Rules?

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.

There are 4 type of business rules.
1. Display BR.
2. Before BR.
3. After BR.
4. Asynch BR.

What is the difference between after and asynch BR?

After BR : This type of BR is used when some field changes needs to be reflected immediately after user saves the record. Mostly used to update/insert record into another table once insert/update/delete operation is performed on current record.

Below is an example where After BR can be used
- On reassignment of incident, add comments in associated problem record.

Asynch BR : As name suggest, it runs asynchronously. Whenever Asynch BR is triggered, system creates new entry in event queue to process. Execution time varies for Asynch BR based on the load on event queue.

What are the different objects accessible in BR?

- Current
- Previous
- gs
- g_scratchpad

Note: Previous object is null in Asynch BR, as there could be multiple updates on same record while BR is in queue for execution which might create conflict on which version needs to be considered as previous.

What is display BR? When to use it? Explain with real time use case?

Display rules are processed when a user requests a record form. The data is read from the database, display rules are executed, and the form is presented to the user.

The primary objective of display rules is to use a shared scratchpad object, g_scratchpad, which is also sent to the client side as part of the form. This can be useful when you need to build client scripts that require server data which is not typically part of the record being displayed.

Real time use case : If logged in user is member of current assignment group then only show description field.

We can write display BR as shown below to check if logged in user is part of current group or not and store result in g_scratchpad object, which later can be accessed in client script to show/hide description field accordingly.

Display BR configuration details :


Display BR Script :


On Load Client Script :

What is query BR? What is primary objective of it? Explain it with real time use case?

Before query business rule gets executed whenever query made to the database on particular table.

The primary objective of query BR is to hide/show records, this could be based on conditions.

Real time use case : Show only active users to all users who is not having admin or user_admin role.

Below BR is OOTB, it checks if user has admin or user_admin role, if yes then it shows all user records else shows only active users.

BR configuration:


BR Script :

What is the difference between query BR and ACL?

1.Query business rules only apply for read access at the row level while ACLs can do CRUD operation at the row and column level.

2. Query BRs will affect a GlideRecord query result where ACLs will not unless we are using GlideRecordSecure class.

3. Query BR shows only those records where filter criteria matched while ACL shows all pages with the restricted records being invisible and a message at the bottom 'some records removed due to security'.

What are global Business Rules?

A global Business Rule is a Business Rule where the selected Table is Global. Any other script can call global Business Rules. Global Business Rules have no condition or table restrictions and load on every page in the system.

Note : The reason we would need to use Global Business rules in the past is if we wanted a custom globally accessible function, such as getMyGroups, or getUser. Now a days we can do the same thing in Script Includes which has less performance impacting way.

How to prevent form submission via Business Rule?

We can use 'current.setAbortAction(true)' in Business Rule script to abort action. This will stop data updation in database.

How to identify if current operation is insert, update or delete in Business Rules?

We can use current.operation() in BR. Depending on current operation, it returns update, delete or insert value.

How to trigger notification via Business Rules?

We can use gs.eventQueue method to trigger notification via business rule.
Syntax : gs.eventQueue('event_name',current,'param1','param2');

What is the result data if we filter only active records through Query BR and add reference qualifier with active =false condition?

It will show 0 records, since query BR gets executed whenever query made to the table which will return only active records and as reference qualifier is adding active =false filter, system will show 0 records.

Assignment for you:

1. Which type of BR shouldn't include current.update() and why?

2. Explain advantages of Asynch BR over After BR or vice versa.

3. Can we call scheduled job from BR?

4. Did you ever called script include in BR? Why we call script include in BR if we can write same script in BR itself?

Real Time Sample Questions:

1. How do you debug BR? What are the different ways to debug BR?

2. Explain any scenario where we can't use Asynch BR?

3. Explain any scenario where we can use Display BR instead of using GlideAjax?


Prepared and confident for your interview? Practice makes perfect! Test your skills with our virtual interview practice buddy and ensure you're fully ready for your upcoming interview. Click here to start.

Fuel My Passion

Loving the content? Well, of course you are. Here’s your chance to indirectly fuel the chaos that keeps this website running. Your contribution helps keep the wheels turning and allows me to continue pretending to be a responsible adult—while cranking out more content for you. Thanks for supporting my delusional dreams and helping me keep this website alive!


Buy Me a Coffee

Support with UPI

If you prefer making a UPI payment to support the website maintenance cost, scan the QR code below:

UPI QR Code

User Added Interview Question and Answers

Harika 2024-12-21 08:27:31

Sir, I am confused about when to use before, after, async business rule? I know what they are and how they work but it seems like what can be done with before can also be done with after, so what's the point of them and next question is if in async business rule there is no current and previous then how we can access the current record while using async business rule? and where should we use trycatch

0 Helpfuls


Sonu 2024-09-09 03:13:29

What is the backend process in service catalog?


tarun teja 2025-03-26 11:08:05
In ServiceNow, the backend process for the Service Catalog involves defining and managing catalog items, their workflows, and the fulfillment processes that occur when a user requests an item, including creating records, assigning tasks, and triggering approvals
0 Helpfuls
0 Helpfuls


Keerthana Arumugam 2024-05-21 07:49:35

How to call business rules from scheduled job


Anil 2024-07-07 02:36:25
you can write BR name in job context , use below syntax JOB CONTEXT: fcScriptName=Business_rule_name
0 Helpfuls
0 Helpfuls


Lakshmi 2024-03-20 08:19:32

What is order of running the rules like which rule runs first business rules ,second Ui policy and so on


Pradeep 2024-04-03 02:47:50
This is my understanding, Query BR -> Display BR -> On Load CS -> On Load UI Policy -> On Change CS -> UI Policy -> Before BR -> After BR -> Asycnh BR
0 Helpfuls
1 Helpfuls


ram 2024-01-29 00:13:51

how to call script include in business rules?


KUSHAL TM 2024-02-02 12:41:24
for example, write below code in your BR. var scrptInc=new yourScriptIncludeName(); scrptInc.functionNameOfYourScriptInclude();
1 Helpfuls
0 Helpfuls


Mounika 2023-11-16 06:58:34

how to call an event through business rule?


Anonymous 2023-11-17 09:16:04
gs.eventQueue('event name',current,parm1,parm2);
2 Helpfuls
0 Helpfuls


Supritha 2023-11-15 09:08:43

What is GlideRecordSecure? What is the difference between GlideRecord and GlideRecordSecure: Answer: GlideRecordSecure is a version of GlideRecord that provides an additional layer of security. GlideRecordSecure is designed to prevent unauthorized access to data. GlideRecordSecure enforces access controls and ensures that the user has permission to access the records they are querying. Developers can then use GlideRecordSecure in the same way as GlideRecord to query and manipulate ServiceNow records. GlideRecord queries and manipulates data in the same way as GlideRecordSecure, but GlideRecordSecure provides additional features for securing sensitive data. This ensures that sensitive data cannot be intercepted by unauthorized users as it enforces access controls. Another difference between the two is performance, Because GlideRecordSecure enforces access controls, it may take longer to execute queries than GlideRecord.

4 Helpfuls


Urmila Mukati 2023-11-05 01:47:17

Interviewer asked me why we use async BR to trigger notification instead of this we can also trigger notification by it's condition itself. Why we need BR can someone please answer?


Venkat 2024-10-10 04:14:48
Business Rule: With an async Business Rule, you can implement complex logic and conditions that may be difficult or impossible to achieve using the standard notification condition builder. This gives you greater flexibility to decide when and how the notification should be triggered. Example: If the notification depends on a combination of factors or involves checking multiple related records, this can be handled in a Business Rule more easily than using notification conditions alone.
0 Helpfuls
0 Helpfuls


Saidulu Yadav 2023-08-25 07:27:22

what is main difference between UI Policy and Client Scripts.


William 2023-10-06 11:26:00
- We can execute client script on submit or on cell edit (list field update) but we cannot execute UI policy on submit or on cell edit. - We can execute client script for specific view but we cannot do the same via UI Policy. - UI Policies are faster as compare to Client scripts, therefore ServiceNow recommends to use UI Policies wherever possible.
0 Helpfuls
Arpan 2023-10-16 18:59:04
UI Policies can be run for a specific view if you uncheck the Global field and then enter the view name you need.
0 Helpfuls
Surendra 2023-10-23 22:44:55
Hi William We can execute client script or UI policy for the specific view as well.
0 Helpfuls
2 Helpfuls


Ranjit 2023-08-07 20:05:22

Whether the g_scarthpad can be used on all the types of client script?


Naveen 2023-08-19 01:03:09
g_scratchpad is used only in Onload Client scripts to get the data from Display business rule.
1 Helpfuls
Roshan 2023-08-24 08:05:47
In most of the use cases, we access it in onLoad client script. However g_scratchpad object can be accessed in all type of client scripts. In fact it can be accessed in UI policy script also. Here is very important use case where it can be used in on submit client script, if we want to validate something on submit of the form but data is not available on client side. Normally we use GlideAjax to get server side data but GlideAjax fails in onSubmit client script (GlideAjax is asynchronous call therefore form gets submitted before GlideAjax returns result). Therefore we can store result in g_scratchpad object in onChange client script and based on value we can restrict form submission in on submit client script.
0 Helpfuls
0 Helpfuls


Ann 2023-06-07 21:56:59

Hi How to autoclose REQ and RITM when task is closed.


Saba Anjum 2023-07-01 06:59:58
to achieve this we can write two BR 1-sc_task 2- on table sc_req_item condition-state changes to closed complete logic 1- var rtm = new GlideRecord('sc_req_item'); rtm.addQuery('sys_id', current.request_item);//request_item is a field of sc_task rtm.query(); while (rtm.next()) { rtm.state = '3'; rtm.update(); } logic2-var req = new GlideRecord('sc_request'); req.addQuery('sys_id',current.request); req.query(); if(req.next()){ req.request_state = 'closed_complete'; req.update();
0 Helpfuls
0 Helpfuls


annin 2023-05-09 05:03:18

Hi I have asked a question when the incident state is closed related problem state should also be closed How can we do this


Gaurav 2023-05-10 06:38:33
We can write After BR as below to achieve this requirement: Table : Incident BR Condition : When state changes to Closed var grProblem=new GlideRecord("problem"); if(grProblem.get(current.problem_id)){ grProblem.setValue("state",3);//3 is closed state back end value grProblem.update(); } Tip : Interviewer later asks why After BR, why not before BR or Asynch BR? short and simple answer is, if we are updating other than current record then we are supposed to use after BR. If script is too lengthy and execution time is high then we can go with Asynch BR (which runs in backend so that user don't have to wait till BR executes)
0 Helpfuls
0 Helpfuls


kiran 2023-04-28 09:09:28

How to trouble shoot if user is not able to login?


Pratiksha 2023-05-04 22:08:16
There could be different reasons why user is not able to login but most common is wrong password or user doesn't exist in ServiceNow. Therefore, we can troubleshoot issue by following below steps 1. Verify if user exist in ServiceNow User(sys_user) table. 2. Try resetting user password.
0 Helpfuls
Astik 2023-12-09 14:23:15
If user is not able to login please check below things 1.User is active 2.user id is not empty 3.Most Important - User is not locked out
0 Helpfuls
0 Helpfuls


Anoynymous 2023-04-17 01:47:29

What if we have before query BR which is filtering data to show only active incidents. what will happen if we use the fix script on the incident(via glideRecord) will it show all the records in the present in the incident table if no addQuery is used?


Anubhav 2023-04-17 21:56:16
If before query BR is adding filter to show only active incidents and if we try to GlideRecord on incident table then it will return only active incidents. Before query BR executes every time action is performed on database, it doesn't matter if database action is performed via UI or via script.
3 Helpfuls
2 Helpfuls


Rishikesh 2023-03-30 04:52:48

Why current.update() in before BR doesn't create recursion call to same BR infinitely?


Akanksha 2023-03-30 05:35:40
System has internal detectors for this and will prevent an endless series of such Business Rule executions, the detection of this has been known to cause performance issues in that instance. Source : https://support.servicenow.com/kb?id=kb_article_view
0 Helpfuls
0 Helpfuls


Riddhi 2023-03-29 06:25:54

I was given a scenario where I said, I can use after BR to achieve it. But, he asked me why After BR? why not before or Asynch BR? I was not able to justify my answer. Can somebody explain what should be the proper answer to this question? this was asked two times to me for different scenario.


Akanksha 2023-03-30 04:39:12
I think answer depends on given scenario. However, below are the short and simple use cases for different BR. Before BR : Use this BR when you want to update anything on current record. If you use After or Asycnh BR for such scenario then you will have to use current.update() which is not considered as best practice. Asynch BR : When you want to perform any operation which takes long time to execute. This way, user don't have to wait for this BR to complete as it runs in backend asynchronously. After BR : When you want to perform any operation on other than current record, it could be record in other table or same table but other than current record. Hope this helps.
0 Helpfuls
0 Helpfuls






🚀 Power Up Your ServiceNow Career

Join a growing community of smart ServiceNow professionals to stay ahead in interviews, sharpen your development skills, and accelerate your career.

Comments

Rahul 2024-10-16 00:44:30
Sir, I am confused about when to use before, after, async business rule? I know what they are and how they work but it seems like what can be done with before can also be done with after, so what's the point of them and next question is if in async business rule there is no current and previous then how we can access the current record while using async business rule? and where should we use trycatch