UI Action to Delete Table Records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 09:00 AM
Hi,
Is there any way to use a UI action button to delete all records from a table? I have tried using client scripts and server scripts along with using GlideAjax but nothing seems to work. Any help appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 09:06 AM
Go To Tables under System Definitions and open the table. There is a ui action 'Delete All Record'. You could use that ui action to delete all records from table. Also right click on the ui action and configure it to get more details about script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 09:09 AM
Using the Delete All Records on the Table record is the best way. If you want to only delete certain records, you can use doit in a background script: Remove All Data from a Table - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 09:13 AM
Ryan,
Time for my Developer soap box: If you're looking at giving this to end users, I would HIGHLY advise against it. Remember, you're not going to be able to recover these records once they are deleted. Maybe you could set an "active" flag?
That being said, if you REALLY want to give this to your end users, your approach should work. UI action + Script Include that does the delete + GlideAjax to tickle the Script Include. I can't think of anything that would be preventing this. I can provide some sample code of you need it.
Hope that helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 09:33 AM
Hi Ryan,
Please use below code as example for deleting all recods from table in UI action
Please modify table name as per your requirement.
- delContractRecords();
- function delContractRecords()
- {
- var gr= new GlideRecord("ast_contract");
- gr.query();
- gr.setWorkflow(false); //Don't fire Business rule,notifications
- gr.deleteMultiple();
- }
Regards,
Sachin