Before Query Business Rule & Dynamic Filter Use Case
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())
{
current.addQuery('assignment_group', '6df8cc46474d02901279750cd36d43e4');
}
else {
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()returnstrueif 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()returnstruefor 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
https://www.servicenow.com/community/developer-articles/before-query-business-rule-amp-dynamic-filter-use-case/ta-p/2918743