- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 07:23 AM
Hi All,
I am trying to set User Criteria for catalog form like if login user is manager then form will be accessible for him.
trying this code but no success, your help will be appreciated.
Script code -
function checkIfManager(){
gs.log(gs.getUserID());
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
gs.log(gr.hasnext());
}
Solved! Go to Solution.
- Labels:
-
Incident Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 08:21 AM
please try this and let me know if that works well
answer = checkIfManager();
function checkIfManager(){
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
return gr.hasNext();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 07:26 AM
How is a manager defined? Is it in the title on the user record? Or a role?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 07:31 AM
Oh never mind I see. If it is a manager for any user. You can try:
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', user_id);
gr.query();
if(gr.hasnext()){
return true;
}
return false;
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
08-18-2020 07:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 08:06 AM
Yes, it should still work. But to be safe you can use:
answer = false;
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', user_id);
gr.query();
if(gr.hasnext()){
answer = true;
}