How to disassociate approvals from workflow before running again?

Zod
Giga Guru

Hi Experts,

I have an approval workflow. In case of rejection, it will be possible to request approval again.

As I do not like to delete all approvals, I need to find a way to just disassociate the approvals that happened before to be able to run the workflow again.

Without doing this, the rejection given before will still "stuck-point" of the workflow as long no other approves are within the approval group.

In the change management, I found some skipt running (new ChangeRequestStateHandler(current).disassociateApprovalsFromWorkflow();) ... but this will not work here, as I'm not using states here so far ... .

Any other option?

Thank you so much!

16 REPLIES 16

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

This works for me in an approval subflow I have in catalog workflows:


var apprRec = new GlideRecord('sysapproval_approver');


apprRec.addQuery('sysapproval', current.sys_id);


apprRec.query();




while (apprRec.next()) {


  apprRec.wf_activity = '';


  apprRec.update();


}


Looks absolutely correct for me and would make sense.


Unfortunately it does not work.


Still the rejected approval "counts" and no new approval will be forced the 2nd time ;-(


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Can you share more of your workflow and the context?   Is it a catalog item or on another task type,etc.


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

If you look at the dissociate function in your instance, you'll see it follows a similar model (though covers group approvals too):



      /**


        * Dissociate approvals from a particular workflow activity to preserve the history.


        */


      disassociateApprovalsFromWorkflow: function() {


              if (!this._gr)


                      return;




              var existingApprovalsGr = new GlideMultipleUpdate("sysapproval_approver");


              existingApprovalsGr.addQuery("sysapproval", this._gr.getUniqueValue());


              existingApprovalsGr.addQuery("state", "!=", "cancelled");


              existingApprovalsGr.setValue("wf_activity", "");


              existingApprovalsGr.execute();




              existingApprovalsGr = new GlideMultipleUpdate("sysapproval_group");


              existingApprovalsGr.addQuery("parent", this._gr.getUniqueValue());


              existingApprovalsGr.addQuery("approval", "!=", "cancelled");


              existingApprovalsGr.setValue("wf_activity", "");


              existingApprovalsGr.execute();


      },