Group Approval in workflow via Workflow Script

Hemachithra
Tera Contributor

Hi guys!

I am struggling with an approval in a workflow.

So, I want to send an approval to a group based on list collector field 'u_group_name' .

I am trying to accompling this with a script in the Approval - Group action in the workflow, but the approval just won't get sent.

I have tried several varieties of the script, and the script runs correctly, but the approval won't send..

 

answer = [];
var list = current.variables.u_group_name.toString();
gs.info('hcv: ' + list);

var listSplit = list.split(',');
gs.info('listsplitGrps: ' + listSplit);

for (var i = 0; i < listSplit.length; i++) {
 var softwareRef = new GlideRecord('u_conduktor_summary');
    softwareRef.addQuery('sys_id', listSplit[i].trim()); // Replace with actual field name and condition
    softwareRef.query();

    while (softwareRef.next()) {
       
           
     var grp= softwareRef.u_servicenow_group_approval.toString();//reference field
   
        answer.push(grp);
    }
    gs.info('Answer arraygrp is: ' + answer);
}

 

 

 

 Answer arraygrp is: ab2af634db49e4d4a00983133996192e
I'm getting the correct sys id of group in scripts but its not setting in workflow .Please help

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

To confirm, you are saying that ab2af... is the sys_id of the intended group record on the sys_user_group table?  Is that group active and contains at least one active member?  What happens when the workflow reaches the approval? (view the executing workflow from the link on the RITM)

yes it is the desired sys id of the group on a custom table .Below is the screenshot of the form to which my list collector variable is pointing to . 

Hemachithra_0-1697140388753.png

When I hardcore the sys id with the 'Group Name' sys id ,it is returning me the right sys id of the group in Background script but when I pass 

var list = current.variables.u_group_name.toString();

I'm getting the output for 'listsplitGrps: undefined' in logs 

 

The approval is marked as approved and is moving to the next stage .

u_group_name is a list collector variable with which table as the List table?  Is the Servicenow Group Approval field on your custom table referencing sys_user_group?  In your logs hcv: shows one or more comma-separated sys_ids, but listsplitGrps is undefined?  Maybe a more helpful log for the split would be 

gs.info('listsplitGrps: ' + listSplit[0]);

but in either case should show you the same sys_id.