Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Disassociate approvals from workflow is not working through UI action

Majji Koteswar1
Tera Expert

We have a custom UI action "Revert to Assess" in Authorize state of a change request. We have got a requirement to make it visible in Scheduled state as well. We are able to go back to Assess state but approvals are not disassociated. The approval records are still visible in the change request. The below highlighted one is not working and even tried wf_activity as empty. It would be appreciated if someone assist me on the same.

 

Script:

var chgState = current.getValue('state');

if (chgState == '-3') { // Authorize
    current.comments = 'Change has been reverted from Authorize back to Assess';

} else if (chgState == '-2') { // Scheduled
 
    new ChangeRequestStateHandler(current).disassociateApprovalsFromWorkflow(); 

    var querystring = "state=rejected^ORstate=approved^ORstate=not requested";
    var app = new GlideRecord('sysapproval_approver');
    app.addQuery('sysapproval', current.sys_id);
    app.addEncodedQuery(querystring);
    app.query();
    while (app.next()) {
        app.setValue('state', 'not_required');
       // app.setValue('wf_activity', '');
        app.update();
    }

    var querystring2 = "approval=rejected^ORapproval=approved^ORapproval=not requested";
    var app2 = new GlideRecord('sysapproval_group');
    app2.addEncodedQuery(querystring2);
    app2.addQuery('parent', current.sys_id);
    app2.query();
    while (app2.next()) {
        app2.setValue('state', 'not_required');
       // app2.setValue('wf_activity', '');
        app2.update();
    }

    current.setValue('approval', 'not requested');
    current.setValue('u_cab_ready', false);
    current.comments = 'Change has been reverted from Scheduled back to Assess';

    var wf = new global.Workflow();
    wf.restartWorkflow(current);

}

current.setValue('state', '-4'); // Assess
current.update();
action.setRedirectURL(current);
 
Thanks,
Majji
0 REPLIES 0