Workflow - Approval script to return approvers based on location > Group > Users > Role

morrix3
Giga Expert

The script I need help with runs in the Approval Workflow for SM.  And it returns an array of approvers based on the Location Selection.  Some groups take care of Locations and within those groups, users with the approval role.

I need help with a script that will do the following to create approvals for Work Orders. 
I have a function that already returns the group's sys id like this: sys_idIN45646546546546546546546s54dfs6df4

My requirements:

  1. Run this function against the 
  1. var groups = new global.SMFilters().filterGroups(current.sys_class_name, current.location, 'dispatch');
  1. Remove the sys_idIN and push any following groups into an array
  2. Once the groups are in an array, go get all the members of those groups and push them into an array
  3. Make the grMembers array unique (ArrayUtil.unique)
  4. Loop through the uniqueMembers and check to see if they have the approver role
1 ACCEPTED SOLUTION

What did not work?

Please try above code in background script with the correct test data it will surely work.
PFA in my PDI.

SaurabhGupta3_0-1668642985151.pngSaurabhGupta3_1-1668643014794.png

 





Thanks and Regards,

Saurabh Gupta

View solution in original post

4 REPLIES 4

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi @morrix3,
Below code is as per your requirement

 

var groups ="sys_idIN0002648a87b25d509850ed390cbb3511,0012ec8a87b25d509850ed390cbb35f8";//Test Data
var grpMemArr=[];
var grpMem= new GlideRecord('sys_user_grmember');
grpMem.addEncodedQuery('group.'+groups+'^user.roles=approver_user');
grpMem.query();
while(grpMem.next())
{
    grpMemArr.push(grpMem.getValue('user'))
}

var au=new ArrayUtil();
gs.info(au.unique(grpMemArr))
 

 

 

 

Regards
Saurabh

 

Thanks and Regards,

Saurabh Gupta

Saurabh:
I appreciate your help. 
It didn't work. 

What did not work?

Please try above code in background script with the correct test data it will surely work.
PFA in my PDI.

SaurabhGupta3_0-1668642985151.pngSaurabhGupta3_1-1668643014794.png

 





Thanks and Regards,

Saurabh Gupta

What did not work?

Please try above code in background script with the correct test data it will surely work.
PFA in my PDI.

SaurabhGupta3_0-1668642985151.pngSaurabhGupta3_1-1668643014794.png

 





Thanks and Regards,

Saurabh Gupta