- 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-19-2023 08:04 AM
@ads can you try below code
answer=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;
}
Regards,
RJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 03:00 AM
Hi @Rahul RJ - I tried with the script provided by you, But Its not working. Can you please check once again.
Thanks
- 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-20-2023 06:15 AM
Thanks @Ankur Bawiskar - The above script worked.