Workflow Approval based on List Collector Variable

Sandy7
Tera Expert

Hi Everyone -

I have a Service Request w/ Workflow tied to it and need to do the following:

1 - I have a variable that is a list collector. I pasted a screenshot of the associated table from where the list collector pulls the data:

The Override Group Setting is the value(s) selected on the Service Request, and the Functional Approval Group is the associated group that needs to approve if that particular override group setting is selected

find_real_file.png

 

2- I am not sure how to set this up ... has anyone been able to make this work successfully? 

I know I need to set up a Group Approval with Advanced checked, but I am unsure of the syntax to use within that activity. I had the following script below I was testing with but that does not seem to work.. it is automatically approving .. 

// Set the variable 'answer' to a comma-separated list of group ids or an array of group ids to add as approvers.
//
// For example:
var answer = [];
// answer.push('id1');
// answer.push('id2');

var group = current.variables.override_settings; //this is the variable name
var getGroupValue = new GlideRecord('u_override_settings'); //this is the table name
getGroupValue.addEncodedQuery('u_override_group_setting'='+group); //this is the column on the table that is the group setting selected
getGroupValue.query();
if(getGroupValue.next())
answer.push(getGroupValue.u_functional_approver_group.toString()); // this is the asscociated approver group

14 REPLIES 14

So,  the way I set it up is: I set up the approval groups within User Administration -- Groups. 

 

Then, I setup the u_override_settings table and in the u_functional_approver_group field, I manually entered the values here and those values match the existing groups I set up.

I hope that makes sense.. I really appreciate your help

 in the u_functional_approver_group field, I manually entered the values here and those values match the existing groups I set up.

Do you enter the name of a group or something else from the group table

and can it be multiple group names?

 

If it is name try this

var group = current.variables.override_settings; //this is the variable name
var getGroupValue = new GlideRecord('u_override_settings'); //this is the table name
getGroupValue.addQuery('sys_id', 'IN',group); //this is the column on the table that is the group setting selected
getGroupValue.query();
while(getGroupValue.next()){

var gr = new GlideRecord("sys_user_group");
gr.addQuery("name", getGroupValue.u_functional_approver_group.toString());
gr.query();
if (gr.next()) {
answer.push(gr.sys_id.toString()); // this is the asscociated approver group
}


}

So here is the table -- the u_functional_approver group field I actually changed to a reference field. I think that makes more sense. And what shows up in the field is the Servicenow Group name. 

the workflow is still automatically approving and advancing at this step.

 

find_real_file.png

As you have updated it reference field 

We need to update the script to 

var group = current.variables.override_settings; //this is the variable name
var getGroupValue = new GlideRecord('u_override_settings'); //this is the table name
getGroupValue.addQuery('sys_id', 'IN',group); //this is the column on the table that is the group setting selected
getGroupValue.query();
while(getGroupValue.next()){
 answer.push(getGroupValue.u_functional_approver_group.toString()); // this is the asscociated approver group
}

Hi, when i update it with this script, the following error occurs:

Illegal access to getter method getMessage in class org.mozilla.javascript.RhinoException

 

 

If I add "var answer = []" at the top of the script, there's no error, however it again just auto approves and does not send any approval to the approval group.