- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 04:27 AM - edited 01-19-2023 06:39 AM
Hi All,
I want to create an user criteria if the user location is one of location1,location2,location3 and the company is not company1, I have tried with the below user criteria script, but Its not working,
Country('location1,location2,location3');
function Country(country) {
var retVal;
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
if ((country.indexOf(usr.location) > -1) && usr.company != 'c3fdaf724782c1102950c261e36d4373') {
retVal = true;
} else {
retVal = false;
}
return retVal;
}
Can anyone help me on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 06:28 PM
use this
1) it's recommended to use user_id instead of gs.getUserID() in user criteria script
answer = checkCondition();
function checkCondition(country) {
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id',user_id);
usr.addQuery('location.name', 'IN', 'location1,location2,location3');
usr.addQuery('company.name', '!=', 'company1');
usr.query();
return usr.hasNext();
}
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
01-30-2023 06:10 AM
@Ankur Bawiskar - Hi, After testing with some users, its not working for the location1, can you please check once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2023 08:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 08:27 PM
@Ankur Bawiskar is user_id containing the logged-in user sysid? if yes then how?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 08:30 PM
yes user_id contains logged in user sysId.
it's defined at platform level
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader