Since the default notification options in JSM are very limited, I was looking into JSM automation to create custom email notifications to send to our clients using different triggers (like creating a ticket or adding a comment). Here is the part of the email that I need help with :
{{#if(not(issue.comments.body.isEmpty()))}}
<span style="font-size: 20px;">Comments :</span>
{{#issue.comments}}
{{#if(not(internal))}}
{{author.displayName}} added a comment {{created.jqlDateTime()}}
{{body.replaceAll("(\[\^.*?\]\n)","[Attachment added]")}}
{{/}}
{{/}}
{{/}}
This lists the comments that are not internal, like this :
Comments :
A, David added a comment 2025-10-06 14:24
[Attachment added]
This is comment #1 with an attachment.
A, David added a comment 2025-10-09 16:25
This is comment #2 without an attachment.
There are two issues with it:
1. The comments are listed from oldest (at the top) to newest (at the bottom). Since this is sent as an email and emails are usualy sorted from newest to oldest, I was looking for a way to reverse the list and display it in that order instead.
2. Instead of replacing the attachment name with [Attachment added] when an attachment is added, I would like it to include the name of the file and get something like this : "File.pdf was added to the ticket,". I tried using the "issue.attachments" list, but it doesn't know when an attachment is internal or not. I also tried matching {{issue.attachments.fileName}} with the comment's body but it looks like it is not possible to access other variables within a {{#list}}{{/}} statement.
For example, this :
{{issue.attachments.get(0).fileName}}
{{#issue.comments}}
{{body}}
{{issue.attachments.get(0).fileName}}
{{/}}
Gave me this :
file.pdf
Comment #1
Comment #2
Instead of this :
file.pdf
Comment #1
file.pdf
Comment #2
file.pdf
Sorry for the long post and thank you for your time.