- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 08:18 PM
How we can differentiate when to use the Before Query BR and Before BR?
Exactly what are the real-time scenarios that we can decide in this type of situation we have to go with Before Query BR so it won't create performance issues to an instance or we can maintain the standard
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 12:00 AM
Hi,
Adding to all, Before a record is saved to the database.Business rules execute after form submission and before the record update in the database. Example: Calculation of priority based on impact and urgency
Before Query Before query Business Rules execute before a query is sent to the database. When a user is not authorized to see all records in a list, the “Number of row removed by security constraints” message appears. Before query Business Rules act like ACL and prevents users from seeing certain records. When access is controlled through a before query Business Rule ,the “Number of row removed by security constraints” message is not displayed and the user does not know access is restricted.
check below links:
https://www.learnnowlab.com/Business-Rules/
If my answer helped you in any way, mark answer as helpfula nd correct.
Thanks and regards,
Megha.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 08:46 PM
Hey Aj,
Before Query BR:
You can use a query BRule that executes before the database query is made to prevent from accessing certain records
Write BRule on ('incident') table --- When before-query
Example Script:-
This example prevents users from accessing incident records unless they have the ITIL role are listed in the caller or Opened by field . So, for ex, when self-service users open a list of incidents, they can only see the incidents they submitted.
if(!gs.hasRole("itil")&& gs.isInteractive()){
var u = gs.getUserID();
var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list","CONTAINS", u);
gs.print("query restricted to user: "+ u);}
Or You can refer the Service Now Docs as well.
There is one OOTB before query BR on user table. it basically checks if logged in user is admin. if not then it will add query as active is true.
It is to restrict other users than admins to see inactive users.
This can be done with ACL also. but advantage of BR is that it will not show any message like, 10 records were hided because of security reasons.
Before BR: After the user submits the form but before any action is taken on the record in the database.
Use to update information on the current object. For example, a business rule containing current.state=3; would set the State field on the current record to the state with a Value of 3.
Please mark it Correct or Helpful, if it works based on impact....!!!!
Best Regards,
Namrata.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 09:17 PM
Hi
There is no DIFFERENCE, a "Before Query BR" is just a more special type of "BR".
Generally a "Before BR" runs BEFORE the Database operation happens, so does the "BEFORE QUERY".
In that specific type of "BEFORE QUERY BR", you can add e.g. Filterconditions for your query to narrow the data shown in the result. (so, to add the filterconditions is BEFORE the database operation - the Query).
For other "Before BR", it will be also ALWAYS specific, like a "BEFORE INSERT" or "BEFORE UPDATE"-
There is NO just "BEFORE BR" which is generally. You alway specify, the database operation, the BEFORE BR will run on.
Let me know, if that answers your questioin and mark my answer as correct and helpful.
BR
Dirk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 09:27 PM
Hi,
You can use a query business rule that executes before a database query is made.
Before a query for a record or list of records is sent to the database.
Typically you should use query for before business rules.
Since they run before the physical update, any changes you make to the record during the rule are recorded as part of the update. This makes before rules the ideal place to set values as part of the save cascade. On the other hand, at the time the before rule is running, the current set of changes hasn't yet written through to the database, and may not be, e.g. the update could be cancelled because of missing mandatory fields, other business rules, etc.
So just simple difference between them is for filtering the data you can use query BR and for all data you can use before BR.
Please mark correct or helpful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 10:00 PM
Hello Aj,
Business Rule is server-side scripting that executes whenever a record is inserted, updated, deleted, displayed, or queried. The key thing to keep in mind while creating a business rule is that when and on what action it has to execute. You can run the business rule ‘on display’, ‘on before’ or ‘on after’ of an action (insert, delete, update) is performed.
Before Business Rule:-
Before Business Rule will, runs before the data saved in the database or in other words, we can say that the actions you give are saved first and then the form gets updated/inserted.
When user click save or update the record
Before
Before Business Rule Script will get execute
Then
Record get to save in the database or in table
Example:-
1. Set field values using scripting.
Sol:-
current.u_email = gs.getUser().email;
2. Abort the action by validating the field value.
Sol:-
If(current.u_email == xyz@gmail.com)
{
gs.addInfoMessage(“You are submitting the right value”);
}
Else {
current.setAbortAction(true);
}
After Business Rule:-
After Business Rule runs when the record is saved in the database. We can use after business rule to react inserts/updates/deletes.
When user click save or update the record
Before
Record get to save in the database or in table
Then
After Business Rule Script will get execute
Example:-
1. Will create the problem ticket through the incident ticket, when user change the incident state field value as “On Hold”
Sol:-
Var configurationitem = current.cmdb_ci;
Var shortdesciption = current.short_desciption;
Var assignmentgroup = current.assignment_group;
Var probobj = new GlideRecord(‘problem’);
probobj.cmdb_ci = configurationitem;
probobj.short_desciption = shortdesciption;
probobj.assignment_group = assignmentgroup;
probobj.insert();
gs.addInfoMessage(probobj.number + ”ticket has been created through incident record”);
Before Query Business Rule:-
Before Query Business Rules are just what they sound like - Business Rules that run before the query on a table occurs. They offer an opportunity to add query terms that will limit the data returned, and can, therefore, act as security measures.
You can visit below link for more info -
I hope this will help you.
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response useful to you and help others to find information faster.
Thanks,
Tejas