Setting 900k emails from send-ready to send-ignored FASTER

hanaphouse
Giga Guru

We have about 915,600 emails stuck in send-ready in our UAT environment. I made a little fix script to set these from Ready to Ignored before enabling the email outbound. When I ran the script, it took me several hours before it clears out and don't want to spend the same amount of time when it happens again.

What's the better approach?
We should be able to clean this out in under a few minutes with a different approach right?

var gr = new GlideRecord('sys_email');
gr.addEncodedQuery('type=send-ready');
gr.query();
while (gr.next()) {
    gr.state = 'ignored';
    gr.type = 'send-ignored';
    gr.update();
}
1 ACCEPTED SOLUTION

Frank Tate
Giga Guru
Giga Guru

Instead of a loop, right after gr.query, you can use gr.setValue and gr.updateMultiple() like so:

var gr = new GlideRecord('sys_email');
gr.addEncodedQuery('type=send-ready');
gr.query();
gr.setValue('state','ignored');
gr.setValue('type','send-ignored');
gr.updateMultiple();

You may be able to use updateMultiple() after setting gr.x, but I've only seen it used after setValue().

Frank

View solution in original post

6 REPLIES 6

Frank Tate
Giga Guru
Giga Guru

Instead of a loop, right after gr.query, you can use gr.setValue and gr.updateMultiple() like so:

var gr = new GlideRecord('sys_email');
gr.addEncodedQuery('type=send-ready');
gr.query();
gr.setValue('state','ignored');
gr.setValue('type','send-ignored');
gr.updateMultiple();

You may be able to use updateMultiple() after setting gr.x, but I've only seen it used after setValue().

Frank

I stopped at 600,000th email and tried using .updateMultiple() but no major change on the speed of setting the emails to ignored.

Hello

Did yu get a chance to check my comments?

Thanks

Saurav11
Kilo Patron
Kilo Patron

Hello,

Please check the below article for recommend method of mass update of record

https://community.servicenow.com/community?id=community_blog&sys_id=60ccee25dbd0dbc01dcaf3231f961946

Please mark answer correct/helpful based on impact