Regarding showing different colors for "Choices of Priority field" in Notification body

Appu2
Tera Contributor

Hi,

I have this notification setup for some table.

Appu2_0-1697776760670.png

 

Here the requirement is to show Priority choices in different colors in the notification like if record has High priority it should be in "red" in the notification ; if Medium then "orange" color in notification and so on for other choices. How to achieve this? Any inputs here?

 

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hi @Appu2 

 

You need to write mail script to assign the color :

 

Step 1 : Create mail script 

Name : priority_color

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

    /* Get priority */

    var getPriority = current.getValue('priority');
    var priority;
    if (getPriority == 1) {
        priority = '<span style="color:red;"> Critical </span>';
    } else if (getPriority == 2){
        priority = '<span style="color:orange;"> High </span>';        
    }  // and so on

	template.print(priority);

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

 

Step 2 : Call that mail script in Notification

 

VishalBirajdar_0-1697781286961.png

 

Output : 

 

VishalBirajdar_1-1697781365253.png

 

VishalBirajdar_2-1697781397027.png

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

7 REPLIES 7

Harsh_Deep
Giga Sage
Giga Sage

Hello @Appu2 ,

 

Use email script for the same. 

Check if priority is low then set color as green and so on.

 

Please mark my answer as helpful and solution accepted.
Thanks

Appu2
Tera Contributor

Hi @Harsh_Deep 

Can you provide me the code for Email script?

Hello @Appu2 ,

 

Please refer this -

https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/script/server-scripting/refe...

 

and for the color coding use this-

template.print('<table style="margin-left: auto; margin-right: auto; border-collapse: collapse; width: 100%; font-family: verdana, geneva; font-size: 8pt;" border="1">');

 

Please mark my answer as helpful and solution accepted.
Thanks

Appu2
Tera Contributor

How to add different colors for choices? The above code didn't gave the color just displayed the priority!