HTML Notification cell background color condition

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 ?


  • Verified Answer

    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>

     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.

  • Hi Helalek2,

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


  • 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>

    ...SM rendered




    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.


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