Recent Comments - Mailscript pulling through updates in one string

Alex Wheeler
Tera Contributor

Hi all,

 

We're currently running through an exercise of updating our notification templates. In doing so, we have established that the ${comments} variable isn't working for us within the HTML we are using for the notifications.

 

As such, we are using a Mailscript to pull through the information instead - ${mail_script:recComments}:

 

 

(function runMailScript(current, template, email, email_action, event) {
var recComments = current.comments.getJournalEntry(3);
template.print("\n" + recComments);
})(current, template, email, email_action, event);

 

 

The mailscript works and is pulling through the three most recent updates, however they are in one continued string and are not displaying any break between each update:

 

AlexWheeler_0-1721896682323.png

 

I'm hoping this is a straightforward fix for someone with more Javascript knowledge than I hold, and would be incredibly grateful if someone could assist by telling me what needs to be amended in the script above to break each update.

 

Thanks in advance,

Alex 🙂 

 

@Terry Carr 

1 ACCEPTED SOLUTION

Bhavya11
Kilo Patron

hi @Alex Wheeler 

 

can you try below code:

 

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

         var recComments = current.comments.getJournalEntry(3);
var formattedComments = recComments.replace(/\n/g, "<br>");
template.print(formattedComments);


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

 

 

Please mark helpful & correct answer if it's really worthy for you.

Thanks,

BK

View solution in original post

3 REPLIES 3

Bhavya11
Kilo Patron

hi @Alex Wheeler 

 

can you try below code:

 

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

         var recComments = current.comments.getJournalEntry(3);
var formattedComments = recComments.replace(/\n/g, "<br>");
template.print(formattedComments);


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

 

 

Please mark helpful & correct answer if it's really worthy for you.

Thanks,

BK

Mark Manders
Mega Patron

You could try something like this:

 

(function runMailScript(current, template, email, email_action, event) {
    var recComments = current.comments.getJournalEntry(3);
    var commentsArray = recComments.split(/\n?-\s/g); // Split comments based on their separator pattern
    var formattedComments = commentsArray.join('\n'); // Join the comments with a line break

    template.print("\n" + formattedComments);
})(current, template, email, email_action, event);

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Alex Wheeler
Tera Contributor

That's worked a treat thanks BK - appreciate your assistance!!