- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 02:36 AM
In the Advanced of user criteria, I want to set the condition that a specific word is included in the department to which the user belongs. Please tell me about the code written in the script.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 03:16 AM
Hi Kurumi,
You can use the below code to make it work.
var loggedInUser = new GlideRecord('sys_user');
loggedInUser.get(gs.getUserID());
if(loggedInUser.department.getDisplayValue().includes('specific word you want to check')){
answer = true;
}
Please mark this as correct and helpful if it resolved the query or lead you in right direction.
Thanks,
Mohit Kaushik
Community Rising Star 2022
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 02:51 AM
Hi,
can you try the below script:
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 03:16 AM
Hi Kurumi,
You can use the below code to make it work.
var loggedInUser = new GlideRecord('sys_user');
loggedInUser.get(gs.getUserID());
if(loggedInUser.department.getDisplayValue().includes('specific word you want to check')){
answer = true;
}
Please mark this as correct and helpful if it resolved the query or lead you in right direction.
Thanks,
Mohit Kaushik
Community Rising Star 2022
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 11:33 AM
I encountered an issue I feel like is important to be aware of, and it is related to the script you wrote here.
Using gs.getUserID() checks the session for the logged in user. If for some reason the logged in user has to run a check against another user, the criteria will still check the logged in user.
Docs page:
https://docs.servicenow.com/en-US/bundle/utah-servicenow-platform/page/product/service-catalog-manag...
Explicitly states "
- Do not use gs.getUser() or other session APIs since they cause conflict when used in diagnostic tools. Use the pre-defined user_id variable available in the script to get the user id of the user being used to evaluate the script.
"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2023 02:30 AM
Hi @Joshua Draper,
Thanks for noticing and bringing that out. I always appreciate if someone finds mistake in my code and that can be corrected. I agree with you this code can be better by using the user_id variable.
Mohit Kaushik
ServiceNow MVP (2023-2025)