x
login Signup

How can I use HTML tags in an Email Notifier from a property value?

We are using the standard email notifier, which we received from an Electric Cloud Field Engineer 10+ years ago. I'm trying to make a small tweak to it by adding an optional field to the main table. My change looks like this and it's working as expected with one small issue (see below):

       $[/javascript if (typeof(myJob.NotifierComment) != "undefined") {
         <tr>
            <td class="success">Comment</td>
            <td class="success">$[/javascript if (myJob.NotifierComment != "") { myJob.NotifierComment.replace(/\n/g, "<br>");}]</td>
         </tr>
       }]

So if the Job property NotifierComment is not set, the Comment row is omitted, and if it is set to something, then it appears as expected. However, any embedded "\n" characters are shown literally and not replaced with "
". Furthermore, if instead I include the "
" in the NotifierComment property, the entire Email Notifier fails with the following error:

 Error [PropertyReferenceError]: couldn't find property 'javascript' used in notifier 'EmailNotify'
 JavaScript error: 'illegally formed XML syntax' at line 6, column 7 near ' }'

So how can I accomplish what I want, namely include HTML formatted comments in the email notifier?

avatar image By alfred 27 asked Feb 01 at 03:22 PM
more ▼
(comments are locked)
10|750 characters needed characters left

5 answers: sort voted first

I coulnd't figure out how to do this in JavaScript in the embedded $[/javascript ...] block, so instead I made sure that the property I'm trying to access was properly encoded before passing it in to the email notifier.

avatar image By alfred 27 answered Feb 11 at 02:35 PM
more ▼
(comments are locked)
10|750 characters needed characters left

use <br/> instead of \n

avatar image By lrochette 5.9k answered Feb 01 at 07:30 PM
more ▼
(comments are locked)
10|750 characters needed characters left

Very interesting. I don't know why this works, but it indeed does. I use "<br>" in other fields that are not checked with javascript, and don't have any issues there. But for this use case I definitely have to use "<br/>".

Thanks, Alfred

avatar image By alfred 27 answered Feb 01 at 07:39 PM
more ▼
(comments are locked)
10|750 characters needed characters left

\n is considered in HTML like a simple space so you need <br>.

However, our HTML is checked against XML and therefore each tag should be closed and it's where <br/> comes into play

avatar image By lrochette 5.9k answered Feb 01 at 07:50 PM
more ▼
(comments are locked)
10|750 characters needed characters left

I encountered a similar issue when trying to update our EmailNotiifier property. Currently, the notified contains the following:

   <tr>
     <td class="success">Git Author</td>
     <td class="success">$[/javascript myJob.gitAuthor]</td>
   </tr>
 

This works as expected. However, the notifier fails with a 'illegally formed XML syntax' error when I wrap it in a conditional:

   $[/javascript if (typeof(myJob.GitAuthor) != "undefined") {
   <tr>
      <td class="success">Git Author</td>
      <td class="success">$[/javascript myJob.gitAuthor]</td>
   </tr>
   }]
 

That is because the gitAuthor property contains something like "John Doe <johndoe@foo.com>". How can I both have the conditional and also display the value of the property as is?

avatar image By alfred 27 answered Feb 05 at 03:16 PM
more ▼
(comments are locked)
avatar image lrochette Feb 05 at 04:31 PM

you will have to parse the property and replace each invalid character, here > and < by & gt; and & lt; (minus the space I introduced to be sure it was not converted) I would not be surprised to hear that JS has a function to do that already

10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.