- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2025 01:40 PM
Hello,
I am trying to add an additional condition to my query business rule that will restrict the catalog only users with the pso_info_security role, It is restricting to the role and opened by but not when I add "requested_for" into the business rule. When I add the requested for, the restriction no longer works. What am I doing wrong? I removed the extra condition. Please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 05:51 AM
try this
(function executeRule(current, previous) {
// If the user does NOT have the pso_info_security role
if (!gs.hasRole("pso_info_security")) {
var userID = gs.getUserID();
var itemID = '448d32c91bdda214d058c992604bcb28';
// Only allow if the user is opened_by or requested_for
// Block the item for others
var encodedQuery = "request_item.cat_item!=" + itemID +
"^ORrequest_item.opened_by=" + userID +
"^ORrequest_item.requested_for=" + userID;
current.addEncodedQuery(encodedQuery);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 07:09 AM
which opened_by are you referring? sc_task or the sc_req_item?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 07:26 AM
Thank you so much Ankur, this works the the only thing I did was changed the dot walk field from requested_item to request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 06:32 AM
Please try with below script and let me know:
(function executeRule(current, previous) {
if (!gs.hasRole("pso_info_security")) {
var userID = gs.getUserID();
var itemID = '448d32c91bdda214d058c992604bcb28';
// Only show the catalog item if user is the opened_by or requested_for
var encodedQuery = "cat_item!=" + itemID + "^ORopened_by=" + userID + "^ORrequested_for=" + userID;
current.addEncodedQuery(encodedQuery);
}
})(current, previous);
Please mark correct/helpful if this helps you!