- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 03:37 AM
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!!!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 04:37 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 02:00 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 02:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 02:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 04:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 04:31 AM
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( );