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

How are you launching the workflow?   Based on conditions on the CI or using a script?  



If the former, can you share a screenshot of your workflow properties where it defines the table that it's against and when to run the workflow.



If it's the latter, can you share the script that invokes the workflow.



Also, can you show a screenshot of the sysapproval and document_id fields on the approval records in question?



Sorry for the laundry list, just want to make sure I understand the context properly.


All fine ... it works like this. Just the 1. line was not correct in your answer. This way it works. Just repost the code please ... than I mark correct for you!


Gotta go now. BIG Thank you & good night ... here close to midnight 😉


//


var apprRec = new GlideRecord('sysapproval_group');    


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


apprRec.query();    


 


while (apprRec.next()) {    


  apprRec.wf_activity = '';    


  apprRec.update();    


}  


Stop - it is working!!


Just change in line 1 to "var apprRec = new GlideRecord('sysapproval_approver');"



Thank you a lot!!!



Could you just send the correct code again - so that I can mark correct?




THANK YOU VERY MUCH!!



stop ... "approval_group" I mean


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

I'm unclear what your last ask is. The last suggestion made was:



var apprRec = new GlideRecord('sysapproval_approver');


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


apprRec.query();




while (apprRec.next()) {


  apprRec.wf_activity = '';


  apprRec.update();


}



I wouldn't just change sysapproval_approver to sysapproval_group as the the group table does not have a document_id field, so the query would end up clearing ALL group approval records wf_activity field.   But you could probably do something like:



var apprRec = new GlideRecord('sysapproval_approver');


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


apprRec.query();




while (apprRec.next()) {


  apprRec.wf_activity = '';


  apprRec.group = '';


  apprRec.update();


}



Hopefully that settles it for you.