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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Untested, though I would go for applying a filter with:

type=send-ready AND deleted=false

Why? Because type,deleted is one of the database indexes on sys_email. For only type, there's no database index out-of-the-box.

Second I would go for updateMultiple, like Frank Tate also mentioned. You don't need the gr.query() there, though it won't hurt also.

Third, since it's such a large number (600.000), I would go for increments, for example 100.000 at a time.

Fourth, since this is just about updating to ignored, you can apply:

gr.setWorkflow(false);

This prevents any possible Business Rules, Flows, etc. from being triggered.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thank you. I can't mark 2 answers as correct but both the info from you and Frank make sense.