The CreatorCon Call for Content is officially open! Get started here.

How to clear the approval records in sysapproval_approver table for the new flow exectuion

Community Alums
Not applicable

Hi Team,

 

We have a custom application and flow written to trigger 5 levels of approval. ie if 1st level approves, the approval will got to 2nd level and so on. 

There is a UI action on the form which is available at each approval level. Once the user clicks on the UI action, it restarts the flow execution as earlier from level 1 but the old approver records are still visible for the new execution

Can someone tell is there is any approach which is OOB or any custom approach wherein I can clear the approval records or via Query Business rule how to restrict the visibility of old approvals?

2 REPLIES 2

J Siva
Kilo Patron
Kilo Patron

Hi @Community Alums 
There isn't an OOB feature to clear approval records. However, you can write a server-side script to delete the existing approval records. Since you are using the UI action to reset the approval, it would be best to have a script that deletes the existing approval records through the same UI action.

var app_records = new GlideRecord("sysapproval_approver");
app_record.addQuery("source_table",<parent rec table>");
app_record.addQuery("document_id",<parent rec sys_id>");
app_record.query();
app_record.deleteMultiple();

 
Regards,
Siva

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

so it's creating fresh approvals and older ones are still show.

In your UI action code you can write logic to delete approvals till that level.

For example at each approval level there is button, how are you determining the approval level.

You can use this script to delete the approvals but remember to delete the correct approval records at the previous level

Note: I assume your UI action is server side

var approvalRec = new GlideRecord("sysapproval_approver");
approvalRec.addQuery("source_table", current.getTableName());
approvalRec.addQuery("document_id", current.sys_id);
approvalRec.query();
approvalRec.deleteMultiple();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader