Catalog item User Criteria Advanced Script not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:30 PM
Hi Experts,
I have a custom String type field on User table named Business (u_business). I have a requirement to make a catalog item available for users who has itil role and have the Business field value as 'Technology and Digital Group'.
I have created a User Criteria under the Available For related list with the below script, but the it doesn't seem to enter the GlideRecord and If-Else query. Can you please help me with the correct script?
function getBizValue() { var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery("active=true^u_business=Technology and Digital Group"); userRec.addQuery("user_name", user_id); userRec.query(); gs.info('Enters 1 '+user_id); gs.info ('User names '+userRec.user_name+':'+user_id);
if (userRec.next()) {
gs.info('Enters 2 '+user_id);
answer = true;
} else {
answer = false;
gs.info('Enters 3 '+user_id);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:40 PM
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 12:08 AM
So you did confirm the function is triggered right?
Did you try the exact same query also for example in background script? Or even on a the list of sys_user? Does that work is the query already not oke?
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:35 PM
Just looking at your script itself, I do notice:
userRec.addQuery("user_name", user_id);
user_id is a sys_id, and you are checking it now against user_name? That will never work.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:36 PM
What is value of user_id ?? are you trying to check for loggedin user ? then use gs.getUserID()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:37 PM
@Trupti94 gs.getUserID() in a User critera = bad practice
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field