How to clear the approval records in sysapproval_approver table for the new flow exectuion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 10:22 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 11:45 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 11:14 PM
@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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader