- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-05-2024 01:38 AM
Before Query Business Rule
Before query Business rule is a special type of business rule in ServiceNow that is used when we want to limit which records can users access from a given table.
This type of business rule runs before a query is executed and can modify the query conditions to filter data based on domain or other criteria.
Use Case :-
current logged in user can only see the incident record (List View) which is assigned
to a assignment group to whom he is part of.
Business Rule :-
if (gs.getUser().isMemberOf('6df8cc46474d02901279750cd36d43e4') && gs.getSession().isInteractive())
{
// If the user is a member of the group and the session is interactive, proceed current.addQuery('assignment_group', '6df8cc46474d02901279750cd36d43e4');
}
else {
// If the conditions are not met (user is not in the group or session is not interactive), return without further action return;
}
Note :-
-
gs.getUser()
: This retrieves the current user object from the GlideSystem (gs) API. Thegs.getUser()
method is used to get information about the currently logged-in user. -
.isMemberOf('6df8cc46474d02901279750cd36d43e4')
: This checks if the current user is a member of a specific group identified by the provided group ID ('6df8cc46474d02901279750cd36d43e4'). The method.isMemberOf()
returnstrue
if the user belongs to the specified group; otherwise, it returnsfalse
. -
&&
: This is the logical AND operator, which combines two conditions. In this case, it connects the previous condition (gs.getUser().isMemberOf('6df8cc46474d02901279750cd36d43e4')
) with the next condition (gs.getSession().isInteractive()
). -
gs.getSession().isInteractive()
: This checks whether the current session is interactive. An interactive session means that a user is actively logged in and interacting with the system, typically through a UI (User Interface). The method.isInteractive()
returnstrue
for an interactive session; otherwise, it returnsfalse
.
Important :- Don't harcode the sys_id .Instead of hardcoding system IDs directly into your script, consider defining them as constants or retrieving them from property after defining it .
use gs.getProperty('Name')
Dynamic Filter
Act as a filter condition to present the data to the user. It is typically involves modifying queries or conditions at runtime based on user input, session data, or other dynamic factors.
It is bascially present on Table ( if the type is reference and when you choose reference table , you can see the option to select dynamic)
All of the Above is shown with use case an Demo Below :-
Hello ServiceNow Family,
Check out the latest video for serviceNow interview preparation with scenarios.
Link :- (Day 3-4) ServiceNow Scenario-Based Interview Question | Before Query Business Rule | Dynamic Filter
- 8,291 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Using ACL also we will restrict data right, can we achive same thing via ACL?
Can we restrict row level data with ACL ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Gillerla Rajesh For an in-depth comparison of Business Rule vs. ACL see Query Business Rules vs. ACL - comparison.
Also, I would recommend reading through the comments of that article for information (and Performance Best Practices for Before Query Business Rules) about the potential performance issues that Before Query Business Rules can cause.
Please ✅ Correct if this solves your issue and/or 👍 if Helpful
"Simplicity does not precede complexity, but follows it" - Alan Perlis