How to create a user criteria with advance script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 04:49 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,
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(); }
Can anyone help me on this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 05:36 AM - edited 01-31-2023 05:40 AM
Try it like this:
var answer = "";
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', gs.getUserID());
usr.addQuery('location.name', 'IN', 'location1,location2,location3');
usr.addQuery('company.name', '!=', 'company1');
usr.query();
if (usr.next()) {
answer = true;
} else {
answer = false;
}
assuming of course that you are supplying actual location Names for location1... and the company Name for company1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 06:47 AM
Hi @Brad Bowman - I have tried with the above script, its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 05:42 AM
Hi @ads ,
You have everything correct but there's a missing reference to the user_id variable. You'll need to replace user_id with the actual sys_id of the user you want to check.
answer = checkCondition();
function checkCondition() {
var userSysId = gs.getUserID(); // replace this with the actual sys_id of the user you want to check
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', userSysId);
usr.addQuery('location.name', 'IN', 'location1,location2,location3');
usr.addQuery('company.name', '!=', 'company1');
usr.query();
return usr.hasNext();
}
This script will return true if the user has a location of location1, location2, or location3, and a company that is not company1. If the user does not meet these criteria, the script will return false.
Regards,
Shravan
Please mark it as helpful if this works for you.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 06:48 AM
Hi @Sai Shravan - I have tried with the above script, its not working.