logo

NJP

Easily rename Notification Email Scripts

Import · Dec 21, 2020 · article

Implement this after Update business rule on your Email Script [sys_script_email] table to update any references to your email notification script when the name is changed

image

    var notifications = new GlideRecord('sysevent_email_action');
    notifications.addEncodedQuery('message_htmlLIKE${mail_script:' + previous.name);
    notifications.query();
    var count=0;
    while (notifications.next()) {
        var body = notifications.message_html;
        reg = new RegExp('\\$\\{mail_script:' + previous.name + '\\}', 'gmi');
        body = body.replace(reg, '${mail_script:' + current.name + '}');
        notifications.message_html = body;
        if(notifications.update())
            count++;
    }
    gs.addInfoMessage(count +" notifications updated with new email script reference");
View original source

https://www.servicenow.com/community/now-platform-articles/easily-rename-notification-email-scripts/ta-p/2320370