Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA ScriptRunner post function send email with created comment

Mark Montminy
Contributor
August 27, 2018

I've got a scriptrunner post function firing that I can't get to reliably include a comment that was created in a prior function during the same transition.

My sequence looks like:

  1. Adds the current user as a watcher
  2. Custom script post-function to add a comment to the issue (the one I want to include)
  3. The Resolution will be set to Done
  4. Set issue status to linked status
  5. Add a comment to the issue if one is entered during transition
  6. Update change history
  7. Re-index an issue
  8. Fire a Issue Resolved event
  9. Send a custom email

My custom email template includes:

<% if (mostRecentComment)
out << "Last comment: " << mostRecentComment
%>

I've tried mostRecentComment, lastComment, and  latestPriorComment.

On rare occasion, it will seem to work, leading me to think it's a race condition. To that end, I've tried inserting another custom script post-function after step 8 that does

Thread.start {
Thread.sleep(10000)
}

Any ideas what I'm doing wrong?

 

1 answer

1 vote
Nir Haimov
Community Champion
August 27, 2018

Hi @Mark Montminy

This will give you your last comment (if you have any comments)

Try it, without sleep or any other timing involve.

<%
def lastComment = com.atlassian.jira.component.ComponentAccessor.getCommentManager().getLastComment(issue)
if (lastComment != null) {
out << "Last comment: " << lastComment.body
}
%> 

Suggest an answer

Log in or Sign up to answer