Set User Criteria only who is manager

Radhe
Tera Expert

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.  

find_real_file.png

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());

}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Radhe 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Willem
Giga Sage
Giga Sage

How is a manager defined? Is it in the title on the user record? Or a role?

Willem
Giga Sage
Giga Sage

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.

https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...

Thank you for your response, it giving me error

find_real_file.png 

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;
}