how can I delete all emails that have not yet been sent

telford
Kilo Contributor

On our DEV instance we have a whole bunch of emails that are waiting to be sent.     How can I delete them so the email queue is empty?  

Please be detailed - I am not a scripter so will likely need clear directions if scripting is the answer.

thanks in advance,  

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Hi Tim,



Something like below should work. Elevate your privileges and execute below script from background.




var gr=new GlideRecord('sys_email');


gr.addQuery('type','send-ready');


gr.deleteMultiple();



Thanks


Srinivas


View solution in original post

3 REPLIES 3

srinivasthelu
Tera Guru

Hi Tim,



Something like below should work. Elevate your privileges and execute below script from background.




var gr=new GlideRecord('sys_email');


gr.addQuery('type','send-ready');


gr.deleteMultiple();



Thanks


Srinivas


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Tim,



Also please note that you can use gr.setWorkflow(false) statement in case you want to disable the trigger of BR/notification on target table.


GlideRecord - ServiceNow Wiki



NOTE : Background Scripts are so powerful you can wreck your ServiceNow system with the right script.   You need to be extra careful in running background scripts.


Deepak Ingale1
Mega Sage

You can also change the type to send-ignored rather than deleting those.