towerofpower256 / davidmac.pro

My personal website
0 stars 1 forks source link

posts/2021-05-07-stop-outbound-emails/ #24

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Quick ServiceNow Code: Clear the outbound email queue

Avoid the headache of accidentally sending out a mountain of old emails by clearing the email queue before enabling "Email sending" on a development instance.

https://davidmac.pro/posts/2021-05-07-stop-outbound-emails/

atomsmasha commented 1 year ago

Nice one! I implemented something similar in the instance I look after, but added it to a UI Action that's visible on the "Outbox" view.

function showConfirmation() {
    if(confirm('This will mark all emails currently in the Outbox as "Send-Ignored". You sure about that?')) {
        g_list.action('UI ACTION SYSID', 'ACTION NAME');  
    } else {
        return false;
    }
}

if (typeof window == 'undefined'){
   clearOutbox();
}

function clearOutbox() {
    var rec = new GlideRecord('sys_email');
    rec.addQuery('type','send-ready');
    rec.query();

    while (rec.next()) {
      rec.type = 'send-ignored';
      // gs.print('Email ' + rec.subject + ' ignored');
      rec.update();
    }
}
towerofpower256 commented 1 year ago

@atomsmasha nice one, that'll save you some time right there!