How to make pre-query business rules work for each logged-in user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 08:23 PM - edited 10-16-2023 08:24 PM
Thank you for your help.
I would like to have my_requests open on the portal for a logged in user user user to see only the records for the department he/she belongs to.
I have the following requirements for department matches
Example:
If the custom department field (reference type) in the record is "ABC DDD" and the department of the logged in user is "ABC EEE", I want to match on the "ABC" part.
I have accordingly created the following pre-query business rule
It worked as expected for the first user who logged in, but when I log in a user from a different department, the display settings for the first user are still there.
How can I dynamically limit what is displayed for each user from a different department?
Condition:
gs.getSession().isInteractive() && !gs.hasrole('custom_table_role,admin')
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var user_dep = gs.getUser().getDepartmentID();
var grdep = new GlideRecord('cmn_department');
grdep.addQuery('sys_id' , user_dep.toString());
grdep.query();
var dep_name;
var dep_cut;
if(dep.next()){
dep_name = dep.name;
dep_cut = dep_name.split(" ")[0].trim(); //"ABC" can be cut out from "ABC EEE".
}
current.addQuery('custom_department_field.name' , 'STARTSWITH' , dep_cut);
})(current, previous);
Best regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 08:30 PM
BR condition ensures whether it will run for logged in user
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader