Script Postfunction to send comments and priority

There was a question about sending issue details and all the comments added on the issue as an email using script post-function.

Solution

1. Try this for priority.

  1. ${issue.priority.name}

2. For last comment try this.

  1. ${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getLastComment(issue).body}

For all comments try this.

  1. <ul>
  2. ${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{'<li>'+it.body+'</li>'}.join('<br>')}
  3. </ul>

If your code is more than one line then try something like this.

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

To generate the baseurl and complete issue url use this code.

  1. <%
  2. def baseUrl = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
  3. def issueUrl = baseUrl+"/browse/"+issue.key
  4. %>
  5.  
  6. <p>Please approved the issue</p>
  7. <p>Issue full url: ${issueUrl}</p>
  8. <p>Issue link: <a href = ${issueUrl}>${issue.key}</a></p>

I hope it helps. In case you want to learn ScriptRunner for Jira, I have a proper course with plenty of guided videos.

Ravi Sagar Newsletter

Want to contact me?