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

Use if condition and check for priority.

Then add style for color.

 

Please mark my answer as helpful and solution accepted.
Thanks

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

Thank you very much. This worked for me!