- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 01:40 AM - edited 07-25-2024 01:41 AM
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:
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 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 02:08 AM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 02:08 AM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 02:08 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 02:22 AM
That's worked a treat thanks BK - appreciate your assistance!!