UI Action to Delete Table Records

rm1996_
Kilo Explorer

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.

4 REPLIES 4

Gurpreet07
Mega Sage

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.


Michael Fry1
Kilo Patron

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 Scott1
Giga Expert

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!


sachin_namjoshi
Kilo Patron
Kilo Patron

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.



  1. delContractRecords();      
  2. function delContractRecords()      
  3. {      
  4. var gr= new GlideRecord("ast_contract");      
  5. gr.query();  
  6. gr.setWorkflow(false); //Don't fire Business rule,notifications    
  7. gr.deleteMultiple();      
  8. }    


Regards,


Sachin