Improve JIRA dashboards by showing the last issue comment

  • Taille du texte: Agrandir Réduire
  • Notifications
  • Imprimer

A quick way to improve your Filter Results gadgets in JIRA dashboards or in the Issue Navigator is to include a column that shows the last comment. Today I will provide a SIL (Simple Issue Language) recipe to do just that. 

This recipe addresses a limitation of JIRA where it is not possible to show the last issue comment. This limitation is being tracked on Atlassian's public JIRA site with key JRA-2734.

Disclaimer: This recipe involves scripting, which is curretnly not possible with JIRA OnDemand. See Restricted Functions in Atlassian OnDemand for more info.

Another Disclaimer: You could also purchase the CCC Last Comment plugin, but why buy countless plugins when you can do a tons of great things with one or two plugins. Plus what I'm about to show you gives you much more flexibility.

 Shameless plug: I contributed the idea of having a getLastComment() routine in SIL.

Ingredients:

How to do it:

Assuming you've installed the KCF add-on in your JIRA instance, you are ready to go.

#1 Create the Last Comment custom field

Go to the Custom Fields section of JIRA Administration, and click on the Add Custom Field button in the top right corner. Click on Advanced in the left column and select SIL Script Custom Field by double clicking on it. Enter Last Comment as the field name, click Next, and (optional)select some screens to add it to. Note that if you're only interested in using the field in dashboards / search results, you don't need to add it to any screens.

#2 Add the SIL Script to the Last Comment field

Ok, so now you've created a SIL Script Custom Field, but it won't work until you add an actual script. The field itself is like a car body, and we're about to add an engine. In order to do so, find your field in the list of custom fields and use the Gear icon b2ap3_thumbnail_JIRA-gear-icon.png on the same line to access the Configure link. On the next screen you'll need to click on Edit SIL Script. That's where you'll paste the following code snippet:

string[] lastCommentDetails = getLastComment(key);

if(!isNull(lastCommentDetails)){
    return lastCommentDetails["text"];
}
return "";

#3 Add the field on your dashboards through the Filter Results gadgets 

As far as the custom field itself, you're already done. The only left to do is to add the field in a Filter Results gadget. Assuming you already have a Filter Results gadget, simply edit the gadget and field the field like so:

b2ap3_thumbnail_JIRA-SIL-add-last-comment-on-filter-results-gadget.png

#4 Add the field in your Issue Navigator

You can also add the field in your JIRA search results. Simply click on the Columns button and add the Last Comment field:

b2ap3_thumbnail_JIRA-SIL-add-last-comment-on-issue-navigator.png

Extra - Improve the Last Comment field to include the name of the last commenter

When I use the SIL Script Custom Field Last Comment, I also like to include the name of the last commenter. Of course, you could decide to create another SIL Script Custom Field called Last Commenter, it's up to you really. Since I'm a JIRA Minimalist, I'd rather have one field do twice the work!

Here is the SIL script you can use to display the name of the last commenter, followed by a colon, followed by the text of the last comment:

string[] lastCommentDetails = getLastComment(key);

if(!isNull(lastCommentDetails)){
    return userFullName(lastCommentDetails["author"]) + ": " + lastCommentDetails["text"];
}
return "";

And you will get something like this:

b2ap3_thumbnail_JIRA-SIL-Last-Comment-Gadget.png

How it works

If you are a keen observer and have some coding experience, you'll notice the variable lastCommentDetails is actually an array. The getLastComment routine I'm calling returns an array with all the information found in the last comment. It contains these properties accessible via array keys:

Key name

Description

id

the id of the issue comment

text the comment text
author the author of the comment
created creation date, as string, can be assigned to a date variable
updatedBy the updater, or empty string if there is no updater
updated updated date, or empty string if there's no update

Knowing that, it's now up to you to customize your Last Comment field to your liking !

This post was tested on JIRA 6.1.3


Update - Handling Comment Visibility

The initial version of the SIL script for the Custom Field did not account for comment visibility. This meant that the user would see the comment, regardless of the visibility of the comment, which could lead to some problems. Here's an updated version of the script.

string[] lastCommentDetails = getLastComment(key);

if(!isNull(lastCommentDetails)){
if(userHasAccessToComment(currentUser(), lastCommentDetails["id"])){ return userFullName(lastCommentDetails["author"]) + ": " + lastCommentDetails["text"];
} } return "";

Of course, you could decide to return a generic message to when the user does not have access to the comment. I chose to hide it completely, following JIRA's way of doing things, a way which I don't always agree with Wink

Update #2 - Choosing the proper renderer

If you have JIRA Power Users that are using markup to add rich comments, these may not show up properly in your Dashboards and/or Issue Navigator. For example, I added a comment which included a very long link. Here is how it appears in my dashboard:

b2ap3_thumbnail_last-comment-borked.PNG

See how the Last Comment is broken here?

This is actually something you can fix fairly easily. The solution is to go through all your Field Configurations and change the Renderer for the Last Comment field.

For example, if we go in the Default Field Configuration and locate the Last Comment field in there. See how Last Comment is using the Default Text Renderer? We need to change that.

b2ap3_thumbnail_jira-last-comment-renderer.png

 

So click on Renderers, and select the the Wiki Style Renderer, then click on the Update button

b2ap3_thumbnail_jira-edit-field-renderer-last-comment.PNG

 

Now unfortunately, you must repeat this task for all your field configurations. But, now you will get the expected result in your dashboards!

b2ap3_thumbnail_last-comment-ok.PNG

 

Big thanks to commenter prasad for letting me know about this, totally forgot to mention it!

dans JIRA Lectures : 29978 22 commentaires

Commentaires

  • Invité
    prasad vendredi, 19 décembre 2014

    just to give more clarity, here is the output of my JIRA query with one of the defect's Last comment
    --------------
    Voilt Wu: Hi Tony,


    wlans/wlan0/wlan-okc='1'

    regards
    --------------

  • TechSolCom
    TechSolCom vendredi, 19 décembre 2014

    Hi Prasad, thanks for your comment.

    I will update this blog post to provide the solution to your problem :)

Commenter cet article

Invité
Invité lundi, 25 septembre 2017