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

Hi @Radhe ,

 

I see you tried marking 2 answers as Correct. Only one answer can be Correct. Kindly mark my answer as correct if it works for you. As it includes the user_id variable, which is a good practice, and I was the first to have a working answer.

Thanks in advance!

Kind regards,

Willem

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

I use the same script, but the catalog item in visible to everyone.
Please let me know what can go wrong.

I am using the same script, still catalog item is visible to everyone
Please let me know what can go wrong.