Hi, so I'm inexperienced and don't know where to look. Basically I am setting up emails to trigger when a comment is left on a particular Project. I would like the emails to have the body text of the comments left.
I am using Scriptrunner and setting an event with Script Listeners. I can successfully call the JIRA issue into the subject line via $issue, a la:
Issue $issue requires changes
In the body of the email, I can use ${issue.description} to pull in the entire description, but I'm interested in the comments. I've shot in the dark with ${issue.comments} and ${getComments($issue).last()} and the like, but I realize I need documentation and help. Could someone point me in the correct direction?
Hi Jonathan
Try the following in the email template
<% def comments = com.atlassian.jira.component.ComponentAccessor.commentManager.getComments(issue)?.collect { "Comment body: ${it.body} | Author: ${it.authorFullName} | Created: ${it.created}" }?.join("<br>") %> $comments
It will add in the email all the comments for the particular issue.
Please let me know if this does the trick.
regards, Thanos
Thanks, Thanos! That definitely works wonders, and I love that I can have all the components in order to reformat as I like!
"Author: ${it.authorFullName}\n Comment body: ${it.body}\nCreated: ${it.created}"
Author: Davidson, Jonathan
Comment body: What I want changed is this.... blah
Created: Tue May 09 11:29:32 EDT 2017
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I marked this as the answer because you are awesome, but if possible, could you expand on how to select only particular comments? If there are multiple comments, your .collect() grabs them all and then spits out the format provided for each one, with the join() stringed between them.
What if I want to select a particular one or the last one?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For anyone interested in the last comment, this also appears to work for pulling only the last comment:
def comments = commentManager.getComments(sourceIssue)
comments.last().body
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johnathan, I also need the last comment. I've tried your suggestion but I can't get it to work. Since I have very little experience scripting, would you be able to give me the exact code to put in my email template to pull only the last comment in an issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Randy,
Ultimately I set the comments into a newly created Issue's description field, rather than sending via email:
import com.atlassian.jira.component.ComponentAccessor def commentManager = ComponentAccessor.getCommentManager() def comments = commentManager.getComments(sourceIssue) if (comments) { def desc = sourceIssue.description
issue.description = '*Manager comment:* ' + comments.last().body + '\r\n \r\n \r\n----\r\n' + desc } else { issue.description = "No comment set upon transitioning task" }
I can't help you troubleshoot, but probably wrap it up in tags and then call whatever you name the variable.
Best,
Jonathan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<% def comments = com.atlassian.jira.component.ComponentAccessor.commentManager.getComments(issue).last()?.collect { "Comment body: ${it.body} | Author: ${it.authorFullName} | Created: ${it.created}" }?.join("<br>") %> $comments
Think it's the addition of .last() in the code that Thanos provided
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jonathan, that definitely helps and I'm able to include the comments in email notifications that gets sent as a post-function. One thing, an issue with no comments prevents the email notification from ever going out. Any ideas on that? Thanks again for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jonathan Davidson I'm sorry some of your posts got caught in our spam quaratine, I have released them all now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Monique vdB, I apologize that there's now a lot of similar posts with approximately the same content. Can I delete them? When editing them, I only see the option to change text, not to delete the post altogether.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jonathan Davidson thanks for changing the text -- now it's obvious which ones to delete. I can do that for you :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's the code in cloning an issue, if you want the last comment, which is where I'd ultimately ended up by the time I wrote my last reply:
import com.atlassian.jira.component.ComponentAccessor def commentManager = ComponentAccessor.getCommentManager() def comments = commentManager.getComments(sourceIssue) if (comments) { def desc = sourceIssue.description issue.description = '*Manager comment:* ' + comments.last().body + '\r\n \r\n \r\n----\r\n' + desc } else { issue.description = "No comment set upon transitioning with Remove access prompt" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.