- 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:14 AM - edited 05-26-2025 07:15 AM
Hello @Rhonda9 ,
Thanks for the update. But isn't that the exact same requirement as for all the other Catalog Items then? Meaning it does not actually matter which Catalog Item the task is related to?
Please allow me to ask the question again in this way, to make sure there is no misunderstanding:
- Scenario 1: Request is for the "itemID" Catalog Item and I am the requester/opened by user.
Can I see the tasks related to this request? (Yes/No) - Scenario 2: Request is for the "itemID" Catalog Item and I am neither the requester nor opened by user.
Can I see the tasks related to this request? (Yes/No) - Scenario 3: Request is for any other Catalog Item and I am the requester/opened by user.
Can I see the tasks related to this request? (Yes/No) - Scenario 4: Request is for any other Catalog Item and I am neither the requester nor opened by user.
Can I see the tasks related to this request? (Yes/No)
PS: I am aware that, if I have the pso_info_security role then the answer will be yes for all 4 scenarios. I only need to know the answers for users who don't have that role.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 07:23 AM
Hello @Robert H I got it to work as expected now but to answer your questions. Scenario 1. Yes Scenario 2. No, Scenario 3. Yes Scenario 4. Yes I needed to change the dotwalk field from requeted_item to requested. This is what I am using .... I have always struggled with scripting. Thank you so much for helping me out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2025 07:48 AM
Hello @Rhonda9 ,
Thanks for clarifying that you are talking about the "Requested for" of the REQ instead of the RITM, and that you are referring to the "Opened by" of the TASK instead of the RITM.
Good to hear that you found the solution yourself, but I would still recommend to write the script without using the "encoded query" syntax, to make it easier to read:
current.addQuery('cat_item', '!=', itemID)
.addOrCondition('opened_by', userID)
.addOrCondition('request.requested_for', userID);
Regards,
Robert
- 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 06:57 AM - edited 05-26-2025 06:58 AM
Thankyou @Ankur Bawiskar I tried this script but it is allowing the opened_by but not the requested_for to see the catalog tasks And that's the problem that I am running into .