Approvals are not set to "No longer required"

MS17
Tera Contributor

Hi All,

I have a requirement that when group approval is triggered for a request, and if any new members added to that group, then that users should also see the approval record.

I have created a after BR on sys_user_grmember table, currently when request is created and group approval triggered and afterwards when i add new users to that group, the users could see the approval record. the issue is when the request is approved by anyone of the group member, other approval records are moved to "no longer required", but newly inserted approvals on sysapproval_approver are not moved to "no longer required", still is in "requested" state.

Any help would be appreciated. Thank you.

 

 

(function executeRule(current, previous /*null when async*/ ) {

    var groupId = current.group;
    var userId = current.user;

    //active group approvals
    var appr = new GlideRecord('sysapproval_group');
    appr.addQuery('assignment_group', groupId);
    appr.addQuery('approval', 'requested'); // only pending approvals
    appr.query();

    while (appr.next()) {


        // approval entry for the new user
        var grpAppr = new GlideRecord('sysapproval_approver');
        grpAppr.addQuery('group', appr.sys_id);
        grpAppr.query();
        if (grpAppr.next()) {
            var newAppr = new GlideRecord('sysapproval_approver');
            newAppr.initialize();
            newAppr.sysapproval = appr.parent;
            newAppr.group = appr.sys_id;
            newAppr.state = appr.approval;
            newAppr.approver = userId;
            newAppr.document_id = grpAppr.document_id;
            newAppr.source_table = grpAppr.source_table;
            newAppr.insert();
        }

    }


})(current, previous);
14 REPLIES 14

Brad Bowman
Kilo Patron
Kilo Patron

If you have a (legacy) workflow with an Approval - Group activity, you'll need to put that within an Approval Coordinator activity to also handle the manual approvals that you are creating with the BR.  I'm not sure if there's an equivalent action necessary for Flow Designer/Workflow Studio.  Also take a look at the createUserApprovals function in the WorkflowApprovalUtils Script Include that the out of box Business Rule calls when a group approval is created to create the user approvals.  Maybe one of these other fields on the approval record that's created is needed by the BR that is updating the State of the others.

var ids = this.getMembersOfGroup(groupApproval.assignment_group);
      var state = groupApproval.approval + '';
      var taskId = groupApproval.parent + '';
      var approvalId = groupApproval.sys_id + '';

      for (var i = 0; i < ids.length; i++) {
    	 var approval = new GlideRecord('sysapproval_approver');
         approval.initialize();
         approval.sysapproval = taskId;
         // fill out reference to task with the in-memory GlideRecord. 
         // When "Approval Events (Task)" runs it will be able to obtain the task type even though it doesn't yet exist in DB
         var target = groupApproval.parent.getRefRecord();
         approval.sysapproval.setRefRecord(target);
         approval.source_table = target.getRecordClassName();
         approval.document_id = target.sys_id +'';
         approval.group = approvalId;
         approval.approver = ids[i];
         approval.wf_activity = groupApproval.wf_activity;
         approval.state = state;
         if (state == 'approved')
            approval.setValue('comments', gs.getMessage('Automatic approval'));
         
         approval.expected_start = groupApproval.expected_start;
         approval.due_date = groupApproval.due_date;
         approval.insert();
      }

 

Hi @Brad Bowman  ,

Thanks for the reply,

I have checked the OOTB BR which you have mentioned and this BR is for creating group approval from workflow, we are triggering group approval from flow designer. Not sure how the user approval created if it is triggered from flow.

Since you are using Flow Designer to ask for the approval from the group, you just need to add an OR Anyone approves Manual User(s) so that it looks similar to this

BradBowman_0-1765548454602.png

When adding this condition, the Manual User(s) criteria is added using the third icon - the rubber stamp, or whatever that's supposed to be with the plus sign

BradBowman_1-1765548549827.png

In this way, if user approvals are added in addition to the ones that Flow Designer adds from the group, any approval will cause all of the others to be 'No Longer Required'.

 

Hi @Brad Bowman  ,

 

We are using approval definition to trigger group approval from flow

 

MS17_0-1765550242882.png

 

MS17_1-1765550340283.png