Reference qualifier to determine manager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2013 04:23 PM
I'd like to set up a reference qualifier on a reference record in a catalog item so that the sys_user table is filtered by manager of the current logged in user. If an employee is requesting an account of a specific type we typically copy existing roles and rights of another user to determine rights and access. I'm trying to prevent somebody from being able to request elevated rights as eventually this function will be handled by Orchestration. I'd want the ref qualifier to only show other users with the same manager, or if it is the manager making the request only users that he/she is listed as the manager for. Not quite sure where to begin with this one so any help is greatly appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2013 05:32 PM
sys_id=javascript:gs.getUserID()^ORmanager=javascript:gs.getUserID()^ORmanager=javascript:gs.getUser().getManagerID()^managerISNOTEMPTY^ORsys_id=javascript:gs.getUserID()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2013 10:55 AM
Thanks Mark. That did the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2014 07:48 AM
*updated 2/11/14 to exclude inactive accounts and to allow 'itil' role unfiltered access
For any who are looking for the OPPOSITE of that; you want to only see people who report to you... you'd have to do javascript:'manager='+gs.getUserID() or something.
But since we required even more logic, I just built a script include with dynamic filtering of anyone who reports up to them. This code finds all your subordinates three levels deep, and will allow "VIP's" to choose themselves, and will allow delegates to choose people who report up to whomever they are delegated to.
Copy the below code and save it as a Script Include with the name directReportQualifier, and then navigate to the desired sys_user reference field that you want to filter. Open its dictionary entry and put javascript:directReportQualifier() as the reference qualifier and it will do all the work!
function directReportQualifier() { //outputs a string built as a reference qualifier with your employees
var otpt = 'active=true^'; //baseline is active=true
if (!gs.hasRole('itil')){ //techs can choose anyone
var me = gs.getUserID();
var nw = gs.nowNoTZ();
var myrec = new GlideRecord('sys_user');
var dflt = 'manager='+me+'^ORmanager.manager='+me+'^ORmanager.manager.manager='+me; //default is three levels deep
if (myrec.get(me) && myrec.vip == true){
otpt += 'sys_id='+me+'^OR'; //VIPs can choose themselves from the list
}
var dels = new GlideRecord('sys_user_delegate');
dels.addQuery('delegate',me);
dels.addQuery('starts','<',nw);
dels.addQuery('ends','>',nw);
dels.query();
while (dels.next()){
var mydelrec = new GlideRecord('sys_user');
if (mydelrec.get(dels.user) && mydelrec.vip == true){
otpt += 'sys_id='+dels.user+'^OR'; //if you're a delegate of a VIP, include the VIP in the list
}
otpt += 'manager='+dels.user+'^ORmanager.manager='+dels.user+'^ORmanager.manager.manager='+dels.user+'^OR'; //if you're someone's delegate, include their employees as well as yours
}
otpt += dflt;
}
return otpt;
}