Displaying the group an approver belongs to

KB15
Giga Guru

I'm looking to add the name of an approver's approval group in a change request. We have a few groups approving and it's hard to keep track of who's approval is for what group. Is this a script or can it be done a simpler way? I'd also like to add this into a notification as well.

1 ACCEPTED SOLUTION

marcguy
ServiceNow Employee
ServiceNow Employee

you would need to add the 'assignment group' column from that group record, which is misleadingly a task record on the sysapproval_group table.



so group.assignment group is the actual group whom this users has approved on behalf of.



Marc


View solution in original post

8 REPLIES 8

randrews
Tera Guru

if you call this function with a user object it will return the first group found for the user...



function set_tam(var1){


  //this function looks up the group the passed in user object belongs to


  //var1 MUST be the user object not just the sid


  var tam = new GlideRecord('sys_user_grmember');  


  tam.addQuery('user',var1.sys_id);


  tam.query();


  if (tam.next()){


      //set the old group on the form


      return tam.group;  


  }


}




if you have the SID and not the whole object use this one...



function set_tam(var1){


  //this function looks up the group the passed in user sid


  var tam = new GlideRecord('sys_user_grmember');  


  tam.addQuery('user',var1);


  tam.query();


  if (tam.next()){


      //set the old group on the form


      return tam.group;  


  }


}


If the user belongs to several groups, would I have a problem with this script? I'm going to assume I'd have to specify a list of groups to return instead of returning the first group the query finds.


it depends on your goal... our policy is one and only one group per user.. so if they are in multiples they get the first one they are in...



if you want to list all groups they are in... define answer as an array in the function and change the if to a while... then instead of returning tam.group   use answer.push(tam.group);... then after the while loop runs return answer


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Maybe I am misunderstanding your question, but out of the box there is an assignment group column on the Approvers related list that shows the group that the user is approving for. Is this what you are after?   If there are multiple groups required to approve the record at the same time then you will see multiple groups show up in the list for the various members.