- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 09:12 AM
HI All,
My requirement is to push opened by "Director" approval for a catalog item. So here what i want to do is to check opened by manager title if his title is manager skip then again check for his manager if title is Director than ask for approval.
Opened by(title is developer) his manager --> manager (title is manager){skip} his manger --> Director(ask for approval)
i tried using the below script by this returns opened by manager approval instead of director
Script:
var answer=[];
var id = current.opened_by.manager;
var ans='false';
for(var i=0; ans=='false';i++)
{
var gr =new GlideRecord('sys_user');
gr.addQuery('sys_id',id);
gr.query();
if(gr.next()){
if(gr.title.indexOf('director') ==-1){
// if(gr.title.toString().toLowerCase() == 'director'){
answer.push(gr.sys_id.toString());
ans='true';
break;
}
else{
id=gr.manager.sys_id;
}
}
}
TIA
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 10:14 AM
I did something similar whereby they wanted to add each person to the approval listing and move up the hierarchy until the appropriate conditions were found. Taking your existing script, I added the logic to get the Manager from the user, then check to see if they have the correct title, then if they do not, move up the hierarchy. See if this works for you:
answer = []; //used to build the list of approvers
var reqUser = current.opened_by.sys_id;
findMgr(reqUser);
//finds the manager of the user
function findMgr(usrID) {
var usrObj = new GlideRecord('sys_user');
if (usrObj.get(usrID)) {
//does the user has a manager
if (!usrObj.manager.nil()) {
var usrMgr = usrObj.manager; //get the current users manager
checkMgr(usrMgr); //run the check manager function
}
}
}
//checks the manager for appropriate approval rites
function checkMgr(mgrID) {
var mgrCheck = new GlideRecord('sys_user');
if (mgrCheck.get(mgrID)) {
//is the manager the Director
if (mgrCheck.title.toString().toLowerCase().indexOf('director') > -1) {
answer.push(mgrCheck.sys_id.toString()); //add to the list
} else {
var usrID = mgrCheck.sys_id; //get the sysID of the current Manager record
findMgr(usrID); //run the find manager function
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 10:06 AM
you can try something like this.
var answer=[];
var id = current.opened_by.manager;
var mtitle = current.opened_by.manager.title;
if( mtitle =='Director') // make sure the tile name is Director
{
answer.push(id);
}
else {
var gr =new GlideRecord('sys_user');
gr.get(id);
if(gr.title == 'Director')
{
answer.push(gr.sys_id);
}
else{
gs.log('No director available');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 10:14 AM
I did something similar whereby they wanted to add each person to the approval listing and move up the hierarchy until the appropriate conditions were found. Taking your existing script, I added the logic to get the Manager from the user, then check to see if they have the correct title, then if they do not, move up the hierarchy. See if this works for you:
answer = []; //used to build the list of approvers
var reqUser = current.opened_by.sys_id;
findMgr(reqUser);
//finds the manager of the user
function findMgr(usrID) {
var usrObj = new GlideRecord('sys_user');
if (usrObj.get(usrID)) {
//does the user has a manager
if (!usrObj.manager.nil()) {
var usrMgr = usrObj.manager; //get the current users manager
checkMgr(usrMgr); //run the check manager function
}
}
}
//checks the manager for appropriate approval rites
function checkMgr(mgrID) {
var mgrCheck = new GlideRecord('sys_user');
if (mgrCheck.get(mgrID)) {
//is the manager the Director
if (mgrCheck.title.toString().toLowerCase().indexOf('director') > -1) {
answer.push(mgrCheck.sys_id.toString()); //add to the list
} else {
var usrID = mgrCheck.sys_id; //get the sysID of the current Manager record
findMgr(usrID); //run the find manager function
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2019 09:47 AM
Thank you it worked!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2019 11:06 AM
Be sure to mark it as Correct so that others will be able to benefit from the solution provided.