Script include to see logged in user is an manager

maneesh3
Tera Contributor

Hi,

I need to write an script include for an catalog item field: (field is an Reference field to user table) where in if User logged is an manager,  then only the manager employee's should be visible in the list of that reference field.

Please help me in this code

 

Thanks for the help!!!!

 

 

 

 

1 ACCEPTED SOLUTION

Karishma5
Tera Expert

hi maneesh,

Try with the following changes in your code:

 

function checkIfManager(){

var employees=[];

var currentUser = gs.getUser(); 

if(currentUser.isMemberOf(­'<Your group name>')){

var gr= new GlideRecord('sys_user');

gr.addActiveQuery();                                  // Filter to return active records.

gr.query();

while(gr.next()){

employees.push( gr.sys_id.toString());  

}

}

else{
var gr= new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
while(gr.next()){
employees.push(gr.sys_id.toString());
}

}

return "sys_idIN"+employees;

}

 

 

Hope it helps.

View solution in original post

15 REPLIES 15

Hi maneesh,

Glad that its working fine for you. Can you again confirm your requirement if i am getting it right or not, You want to check if the logged in user belongs to some group and you want to display different set of users for that?

maneesh3
Tera Contributor

HI Karishma,

 

Exactly you got my needed requirement. I want to display different set of users if user logged in belong to some group. Please help me in that IF condition in same script. Thanks for your response.

 

 

Thanks

Karishma5
Tera Expert

Hi maneesh,

You can try as follows, just a sample script :

function checkIfManager(){

var employees=[];

var currentUser = gs.getUser(); 
if(currentUser.isMemberOf(­'<Your group name>')){

//some code 

employees.push( );  // push the sys_ids of the users you want to display into the array same as we did earlier

}


else{
var gr= new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
while(gr.next()){
employees.push(gr.sys_id.toString());
}

}

return "sys_idIN"+employees;

}

Hope it helps. 

Hi Karishma,

Once again this is very useful and I am happy for the response only final help is that I need to display all active users when logged in user is belong to the group. Can you please include that in the code I have tried below line but did not work:

 

return 'active=true^manager=true';

 

Please correct me.

 

Thanks a lot. 

 

Hi Karishma,

 

Once again thanks very much for above code. I grateful to the response. Final help in the code, I want to display active users in the list whenever user logged is from a particular group, can you please help me in this. I tried below and did not work:

var employees=[];


var currentUser = gs.getUser();
if(currentUser.isMemberOf('XYZ')&&(gs.getUserID =='00b609034bf103f0003f8050987706a')){


//some code
return 'active=true^manager=true';

employees.push( );