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

What does that give you over the out of box Ask for Approval action with this functionality built in?

We are not using ask for approval action, if anyone approved from group, others are moving to no longer required. 

 

MS17_1-1765551473097.png

 

I get that.  I'm wondering why you are not using the intended out of box Ask for Approval action.

Because this flow we are using it for multiple catalog items, so using approval definition we are triggering dynamic approval (user/group) for different catalog items.

Honestly, I don't know that much about approval definitions - haven't had the need to use one, but I don't like it in this case.  Flow Designer has a mechanism for creating the user approvals and handling what happens when a record is approved or rejected, so you should try to use that.  Since you are adding approvals after the fact, and the Flow Designer action has a way to accommodate that, I think you'd have to use what I showed earlier.  You can add a flow variable or whatever to the flow to incorporate your dynamic approval.

 

You might also be able to keep what you have and add a parallel action with just the manual approval.  I'd need to see the details of each relevant step to troubleshoot that.  Are the user approval records that are created via the approval definition populated with anything in the wf_activity field?  This was used in legacy workflows, but maybe also in this case.