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

No task or catalog item ... in fact some cmdb_ci approval .. . Nothing OOB.



It's a group arroval ... so that might be the issue.



The code above ... this one should work within WF "run script" ? ... Sorry. Late already and I'm a low-code guy 😉


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Yes, it should be a 'Run Script' activity before re-entering the approval activity.   Below is where I have my in my catalog item.   But I can't imagine why it wouldn't work even on a CI.   Though since you are doing group approvals, may be worth trying the second part of the disassociate function:


Screen_Shot_2017-05-10_at_4_48_46_PM.png


run script.JPG


Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Actually I think I may know why it didn't work for you.   Mine was a task based approval so sysapproval (a task reference) is usually where you go to get the task reference of an approval.   Since you are working with CIs, you cannot use the task reference.   There is another non-table specific field that we'll want to use, document_id.



Try this instead:



var apprRec = new GlideRecord('sysapproval_approver');


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



while (apprRec.next()) {


  apprRec.wf_activity = '';


  apprRec.update();


}


;-(


Also not working ...