- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 09:35 AM
Hello all,
I am trying to make a catalog item available to certain users. I was recommended to use the advanced check box under user criteria and query the user table to return the users who fall under certain categories. I can do this in two ways, first we have a field in our user profiles called "Primary Security Affiliation" and I am trying to exclude if those users are under Student, Student Assistant, Student Applicant, or I can also exclude those without a job code since our students have that as empty.
Anyone who guide me in the right direction because I'm new with all the scripting. We are on Istanbul UI16.
Thanks in advance,
Grace
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:47 PM
Use this code, it should work now
checkUsers();
function checkUsers(){
var gr= new GlideRecord('sys_user');
gr.addEncodedQuery('<add your encoded query here>'); //here you will need to set you conditions in the filter and then copy the query. refer section3 in this link Encoded Query Strings - ServiceNow Wiki
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(!gr.hasNext()){
return true;
}
else{
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:37 PM
Did you try with the other script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:43 PM
Just tried and it wasn't successful. If it worked for you then I think I may be missing a step.
1. New User Criteria
2. Added the script and did this for both the catalog item and its category
3. Refreshed and tried logging in with a student account to verify
Student was still able to see the form in Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:46 PM
Got you! i believe there is a misunderstanding in the requirements. If the current user is a student, should he see the catalog item or not?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:55 PM
If the current user is a student, student assistant or student applicant, they should not be able to see the form. Thank you soooo much Abhinay your code below worked! Thank you again for all your help and patience!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 03:47 PM
Use this code, it should work now
checkUsers();
function checkUsers(){
var gr= new GlideRecord('sys_user');
gr.addEncodedQuery('<add your encoded query here>'); //here you will need to set you conditions in the filter and then copy the query. refer section3 in this link Encoded Query Strings - ServiceNow Wiki
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(!gr.hasNext()){
return true;
}
else{
return false;
}
}