Get the top manager

kimberleyohana
Kilo Contributor

Hello, while working on a workflow, I need to get the approbation from the top manager who is in the XYZ group of the user for whom the item is requested for.

My script can only check if the manager and the manager's manager are in the XYZ group.
How can I make my script more dynamic to get the Nth top manager ?

var answer =[];

var manag = current.variables.requested_for.manager;

var supmanag = current.variables.requested_for.manager.manager;

function getManager(){

  var gr = new GlideRecord('sys_user_grmember');

  gr.addQuery('user', manag.sys_id);

  gr.addQuery('group', 'XYZ_sys_id');

  gr.query();

  if(gr.next()){

  answer.push(manag.toString());

  }

}

function getManagerMan(){

  var gr1 = new GlideRecord('sys_user_grmember');

  gr1.addQuery('user', supmanag.sys_id);

  gr1.addQuery('group', 'XYZ_sys_id');

  gr1.query();

  if(gr1.next()){

  answer.push(supmanag.toString());

  }

}

if(!manag.isNil())

{

  if(!supmanag.isNil()){

  getManagerMan();

  }

  else{

  getManager();

  }

}

else if(manag.isNil())

{

  answer.push('sysadmin_id');

}

7 REPLIES 7

Chandu Telu
Tera Guru
Tera Guru
Hi Team

 

I need to check the below hierarchy for current user in service-now.

I can check this hierarchy but unfortunate if any some put any of the any low-level person is manager of another top-level user it’s leading to a loop

Ex: In the below image

If any user by mistakenly put L4 Person is manager of l2 the system going to loop between the L2 and L4 User

Please help me on this

Chandu Telu
Tera Guru
Tera Guru
Hi Team

 

I need to check the below hierarchy for current user in service-now.

I can check this hierarchy but unfortunate if any some put any of the any low-level person is manager of another top-level user it’s leading to a loop

Ex: In the below image

If any user by mistakenly put L4 Person is manager of l2 the system going to loop between the L2 and L4 User

Please help me on this

I'm not clear what your objective is. Can you give an example of what is working or not, and how you would like it to with sample data?