Need help in email script

nameisnani
Mega Sage

Hi Team , 

 

can anyone please help me on this 

 

Daily we are doing ServiceNow health check up -  data will capture in a xls . 

nameisnani_0-1760609058909.png

 

 

we have created a custom table 

nameisnani_1-1760609100920.png

 

and once the record submitted we need trigger a notification 

 

nameisnani_2-1760609173081.png

 

we want to add coloring format based on the value selected for exmple - mid server down means Red color - 

if UP green color

nameisnani_3-1760609254759.png

 

like below 

nameisnani_4-1760609291523.png

 

 

please help me how to do this 

 

please provide me the configuration steps 

8 REPLIES 8

@nameisnani 

what did you start from your side and where are you stuck?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nawal Singh
Tera Guru

Hi @nameisnani ,

 

Please refer below links that will help you!

 1. https://www.servicenow.com/docs/bundle/xanadu-platform-administration/page/script/server-scripting/c...

 

2. https://www.servicenow.com/community/developer-forum/how-do-i-script-creating-a-table-in-a-mail-scri...

 

3. https://www.servicenow.com/community/itsm-forum/email-script-create-html-table-for-the-users-listed-...

 

Please review and try to implement !!

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh

 

nameisnani
Mega Sage

@Ankur Bawiskar 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    (function() {
        function getColor(status) {
            if (status == 'DOWN') return '#ff4d4d'; // Red
            if (status == 'UP') return '#4CAF50'; // Green
            return '#d9d9d9'; // Grey (for unknown)
        }

        var html = '';
        html += '<table border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;width:80%;">';
        html += '<tr style="background-color:#f2f2f2;"><th>Field</th><th>Status</th></tr>';

        // MID Server - Prod
        html += '<tr>';
        html += '<td><b>MID Server - Prod</b></td>';
        html += '<td style="background-color:' + getColor(current.u_mid_prod_status) + ';color:white;text-align:center;">' +
            current.u_mid_prod_status + '</td>';
        html += '</tr>';

        // MID Server - Stag
        html += '<tr>';
        html += '<td><b>MID Server - Stag</b></td>';
        html += '<td style="background-color:' + getColor(current.u_mid_stag_status) + ';color:white;text-align:center;">' +
            current.u_mid_stag_status + '</td>';
        html += '</tr>';

        // MID Server - Dev
        html += '<tr>';
        html += '<td><b>MID Server - Dev</b></td>';
        html += '<td style="background-color:' + getColor(current.u_mid_dev_status) + ';color:white;text-align:center;">' +
            current.u_mid_dev_status + '</td>';
        html += '</tr>';

        html += '</table>';
        html += '<br>Regards,<br><b>ServiceNow Health Check Automation</b>';

        return html;
    })();


})(current, template, email, email_action, event);

 

this is the script i tired  

@nameisnani 

looks fine to me

what debugging did you do?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader