Display the Last Comment for JIRA issues

  • Post author:
  • Post category:Blog
  • Post comments:1 Comment
  • Reading time:1 mins read

Cause

  • In JIRA we can add multiple comments for one issue but we cannot view those comments in the issues navigator due to the comment field is not available to display in the JQL search.
  • You want to see the last comment for issues returned by your query

Solution

We can resolve the problem by using the Adaptavist ScriptRunner Custom field as below

  • Go to JIRA Administration | Manage apps | ScriptRunner | Fields
  • In the Script Fields screen click on the Create Script Field button then Custom Script Field selection on the next screen
  • In the Custom Script Field providing enough info and add the following script
/**
* Field name: Last Comment
* Template: Text Field (multi-line)
*
* Description:
* Returns the last comment on an issue.
*
*/

import com.atlassian.jira.component.ComponentAccessor

// get the latest comment
def commentManager = ComponentAccessor.getCommentManager()
def comment = commentManager.getLastComment(issue)

// check to see if comments exist - return comment body if so
if (comment != null) {
return comment.body
}

return null

The final as picture below

Credit

This Post Has One Comment

  1. Gurmeet Singh

    Wow !! This thing works. HIghly recommended.

Leave a Reply