- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 07:43 AM
I've created the below script to cancel emails that are in the queue in a ready state in order to keep them from being sent out. When I tested it in DEV, it changed the state to ignored but then it still processed the emails when I turned on email send/receive. I don't have access to the test mailbox so I don't know if they actually got processed or not or if they were ignored. I do know that they were not in the skipped emails.
Here's the script. Any idea where I went wrong?
var gr= new GlideRecord('sys_email');
gr.addEncodedQuery("mailbox=outbox^state=ready^sys_created_on<=javascript:gs.dateGenerate('2020-09-02','23:59:59')");
gr.query();
while(gr.next()){
gr.setWorkflow(false); //prevent running business rule
//gs.print('Created on ' + gr.sys_created_on + "State: " + gr.state);
gr.state='ignored';//cancelled state
gr.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 08:20 AM
if still not working, can you give a try with below script. this should work.
var gr= new GlideRecord('sys_email');
gr.addEncodedQuery("mailbox=outbox^state=ready^sys_created_on<=javascript:gs.dateGenerate('2020-09-02','23:59:59')");
gr.query();
while(gr.next()){
gr.state='ignored';//cancelled state
gr.type='send-ignored';
gr.setWorkflow(false); //prevent running business rule
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 07:47 AM
try now
var gr= new GlideRecord('sys_email');
gr.addEncodedQuery("mailbox=outbox^state=ready^sys_created_on<=javascript:gs.dateGenerate('2020-09-02','23:59:59')");
gr.query();
while(gr.next()){
gr.state='ignored';//cancelled state
gr.setWorkflow(false); //prevent running business rule
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 07:48 AM
make sure you added correct state value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 07:47 AM
Hello Keith,
Below is the updated script.
var gr= new GlideRecord('sys_email');
gr.addEncodedQuery("mailbox=outbox^state=ready^sys_created_on<=javascript:gs.dateGenerate('2020-09-02','23:59:59')");
gr.query();
while(gr.next()){
gr.setWorkflow(false); //prevent running business rule
//gs.print('Created on ' + gr.sys_created_on + "State: " + gr.state);
gr.state='send-ignored';//cancelled state
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2020 08:26 AM
I tried your script and it didn't work. It set the state to send-ignored but it was in blue because there is no state of send-ignored. When I turned the notifications back on, they still sent