Highlighted
Valued Contributor.
Valued Contributor.
1052 views

HTML Notification cell background color condition

Jump to solution

Hello guys,

I am trying to send a HTML Notification for change approvals and I want to highlight the risk of the change. I want to make the background color of the cell red if the risk assessment of the change is high or critical.

Can anyone sugest something ?

Thanks,

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: HTML Notification cell background color condition

Jump to solution

You didn't provide your current HTML template you're working with, so I can only give an example and your task is to fit it to your case.

Your first task is to write a code which checks the risk assignment and assigns hex code to a variable accordingly.

So let's start with Expressions tab of your HTML template. Quite often in out-of-box Change Management HTML templates is a following line:

var _risk = $RECORD.risk_assessment;

 I'll use the _risk variable in my examples to hold ticket's risk assessment value, you can use it or $RECORD.risk_assessment, whichever you prefer.

(BTW, Out-of-box SM assumes high risk values are 4 and 5. But please change the "thresold number" to suite your environment of risk assessment numbering.)

The code I did is following:

if (_risk>3) { var riskcolor="#ff0000";} else { var riskcolor="#00ff00";}
var risklabel="<p style=\"BACKGROUND-COLOR: "+riskcolor+"\";>"+_risk+"</p>";

This requires a bit explaining. At least in my case, SM converted some variables I put to the HTML code into a hex color codes. Conversion happened after saving. Maybe it's only my environment, but take that into account when rating my answer.

So my solution was ruthlessly to create a separate <p>-section (paragraph) in a Javascript code and put it inside of <td>..</td> tag pair in a HTML side. By doing that, SM HTML parser doesn't encode color code variables away.

Anyway, first row calculates which color to use - red (#ff0000) is for riskier and green (#00ff00) for safer tickets. Next row assigns this variable to row that creates a HTML paragraph.

So, go to HTML source tab of template, click "source" and add a following section into list of other ticket attributes.

    <tr bgcolor="#f8f9f9">
       <td align="right">Risk Assessment</td>
        <td>{risklabel}</td>
     </tr>

 Save the template and try different tickets in a preview if it does what you wanted. At least in a preview, I was able to change the background color of the cell depending on ticket's risk assessment value.

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish

View solution in original post

4 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: HTML Notification cell background color condition

Jump to solution

You didn't provide your current HTML template you're working with, so I can only give an example and your task is to fit it to your case.

Your first task is to write a code which checks the risk assignment and assigns hex code to a variable accordingly.

So let's start with Expressions tab of your HTML template. Quite often in out-of-box Change Management HTML templates is a following line:

var _risk = $RECORD.risk_assessment;

 I'll use the _risk variable in my examples to hold ticket's risk assessment value, you can use it or $RECORD.risk_assessment, whichever you prefer.

(BTW, Out-of-box SM assumes high risk values are 4 and 5. But please change the "thresold number" to suite your environment of risk assessment numbering.)

The code I did is following:

if (_risk>3) { var riskcolor="#ff0000";} else { var riskcolor="#00ff00";}
var risklabel="<p style=\"BACKGROUND-COLOR: "+riskcolor+"\";>"+_risk+"</p>";

This requires a bit explaining. At least in my case, SM converted some variables I put to the HTML code into a hex color codes. Conversion happened after saving. Maybe it's only my environment, but take that into account when rating my answer.

So my solution was ruthlessly to create a separate <p>-section (paragraph) in a Javascript code and put it inside of <td>..</td> tag pair in a HTML side. By doing that, SM HTML parser doesn't encode color code variables away.

Anyway, first row calculates which color to use - red (#ff0000) is for riskier and green (#00ff00) for safer tickets. Next row assigns this variable to row that creates a HTML paragraph.

So, go to HTML source tab of template, click "source" and add a following section into list of other ticket attributes.

    <tr bgcolor="#f8f9f9">
       <td align="right">Risk Assessment</td>
        <td>{risklabel}</td>
     </tr>

 Save the template and try different tickets in a preview if it does what you wanted. At least in a preview, I was able to change the background color of the cell depending on ticket's risk assessment value.

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish

View solution in original post

Highlighted
Valued Contributor.
Valued Contributor.

Re: HTML Notification cell background color condition

Jump to solution

Hi Helalek2,

Your solution worked. My initial thought was to change the table cell background colour, but this will have to do for now.

Thanks,

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: HTML Notification cell background color condition

Jump to solution

Also I thought that first. You can try this by yourself, but like I said, when I saved this HTML code

 

<tr bgcolor="{riskcolor}">
       <td align="right">Risk Assessment</td>
        <td>{_risk}</td>
</tr>

...SM rendered

bgcolor="{riskcolor}"

to

bgcolor="#FF0000"

Somehow SM took the variable's value and put it as a static value to HTML code. I don't know if it's a flaw or a feature.

 

---
Moving on, this account is no longer active. Best regards, Kelalek
- So Long, and Thanks for All the Fish
0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

Re: HTML Notification cell background color condition

Jump to solution

This is what I initially did and I had the same behaviour.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.