- 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-11-2018 04:12 AM
checkIfManager : function() {
var gr = new GlideRecord("sys_user");
gr.addQuery("manager", gs.getUserID());
gr.setLimit(1);
gr.query();
return gr.hasNext(); // If user is manager for any of d employee in sys_user table
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2018 08:28 PM
Thanks Deepak for the script.
I need to call this script include in catalog item field, so now when user logged in is a manager then in this field only his/her employees should be visible. Can you please help me in the script that may need little change in your logic.
Thanks a lot for this help!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 12:51 AM
hi maneesh,
You can create a classless script include for this with the following code :
function checkIfManager(){
var employees=[];
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;
}
And in the catalog item field, you can right click on the field label and go to configure dictionary and in the reference specification section, select use reference qualifier field as Advanced and in the Reference qual field you can call your script include as follows and save the changes:
javascript : checkIfManager()
Hope it helps.
Regards,
Karishma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2018 01:32 AM
Thanks a ton Karishma, Its working as expected. Also can you please help me in writing an if condition loop in the same script and return values for that field. Can you please give me sample.
Like I want to check in IF condition some group membership and for that user logged in I want to make different list of results.
Thanks again