Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get last comment in filter or JQL?

Do you want to monitor the last comment added to the issue? If you're a Jira user and it’s essential for you to get to know who and when has added the last comment, follow this short step-by-step guide.

LinkedIn (12).jpg

Step 1

First of all, you need to create a new custom field in the project for every Issue type. Type the name “Last Comment” for a custom field and choose the “Paragraph” type (as it is displayed in the screenshots below).

How to get last comment 1.1.png

Note: You should perform a step with adding a Custom field for each Issue Type (in our case these are e.g. Bug, Task, and Story as it's shown on  the screenshot)

Step 2

Then start the Automation process. Here’s what you should do:

Go to Project -> Setting-> Apps-> Project Automation -> Create rule

You can start when the Issue is Commented on and edit a custom field with the latest Comment. 

{

"fields": {

"Last Comment" :"[~accountid:{{comment.author}}] commented: {{issue.comments.last.body}}"

 }

}

2.1.png

Note:

  1.  Last Comment (highlighted in red color)  is a field name. If you name your field differently, please, specify the correct field name there. 
  2. You can format the text template based on which the message will be formed (highlighted in yellow). Copy the pattern from the example and  mention the author of the comment: [~accountid:{{comment.author}}] and display the text of a comment - {{issue.comments.last.body}}

Look at the screenshot below to get a clear view of how to do that properly.

 How to get last comment 2.2.png

Step 3

Go to JQL or native search, or any add-on.

 (for example Time in Status for Jira Cloud) -> Columns -> Select Last Comment field

As a result, you will see the custom field you have created with the latest value.

 How to get last comment 7.7.png

That’s all!

Now you know how to display the last comment in the filter, JQL, or any add-on too. 

If you want to track the time frames and team efficiency in your workflow process in a single safe place, you can try the Time in Status for Jira Cloud add-on. It helps to identify bottlenecks, prevent delays and increase work effectiveness. Have any doubts? Try it on the Atlassian Marketplace and enjoy the results. Your team will be fully satisfied with the provided functionality. 

Best Regards

SaaSJet Team

29 comments

Comment

Log in or Sign up to comment
Chris Thomas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2022

Thanks for this. Without this article I wouldn't have been able to get this working.

 

However I couldn't get the above to work, I needed the following:

 

{
"fields": {
"customfield_10XXX" : "{{issue.comments.last.body}}"

}}

Florian Lenz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 28, 2022

Thanks for the article!

In ended up using the same code Chris posted.

However, is there any way to keep the original formatting of the comment?

E.g. including bullet points, maybe even links to other issues, etc.

Like Florian Demleitner likes this
Louise Woods September 23, 2022

Thanks really helpful article! 

Just wondering if there is a way for just the user display name and comment to appear than the script part showing as well in the filter ?Capture - Last Comment.PNG

Chris Thomas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2022

@Louise Woods Mine does not show the JSON brackets. Just a couple of thoughts:

  1. You could switch out the Last Comment in the code with the customfield_XXXXXX name.
  2. Disable the current automation and create a new one from scratch following the instructions.
Louise Woods September 23, 2022

Chris Thomas Thanks for your help it I have worked it out!

LaurenS October 28, 2022

when I tag a specific user in the comment, JIRA reflects the account number as opposed to the name of the user in the 'Last Comment' field  How can this be fixed?

For example

most recent Comment :  (@ jane smith) can we rename the report?

Comes up in Last Comment in filters and dashboards as :

accountid:12345:123xx123-xx5x-4141-x05x-715x9100x1x8 can we rename the report?

Carl Palmquist November 2, 2022

Thanks for all this! Super useful, how would the code look like if I wanted to also add the Date when the last comment was made? in a YYYY-MM-DD or similar

Like Robyn Lorenz likes this
Tomas Arguinzones
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 4, 2022

Hi @LaurenS ,

 

were you able to fix that? same problem here.

Thank you

LaurenS November 4, 2022

@Tomas Arguinzones nope, haven't been able to figure it out

Tomas Arguinzones
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 4, 2022

Hi @LaurenS 

I just figured it out!

Just change the renderer in the field configuration scheme for the field from free text to wiki style and it did the trick!

Like # people like this
Emil Moses November 6, 2022

Hi @Tomas Arguinzones  @LaurenS 

Tried to not resolved in last comment 

free text to wiki style received account id : 

Hi [~accountid:62c6c10a5f45fds3d3b7b76f5a] ,

Issue resolved please verify ,

Screenshot 2022-11-06 225058.jpg

LaurenS November 7, 2022

issue resolved! thank you very much @Tomas Arguinzones 

Emil Moses November 7, 2022

@LaurenS 

Can you please let me know how did you resolved am still getting the same issue 

Hi [~accountid:62c6c10a5f45fds3d3b7b76f5a] ,

Issue resolved please verify ,

If anyone tagged in the last comment it only gives me there iD 

{{issue.comments.last.body}}

Robyn Lorenz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 21, 2023

Did anyone ever figure out how to post the date of the last comment in that custom field?

Having the last comment is useful, but having the date in there of when it was posted would be helpful as well.

Like Carl Palmquist likes this
Randall Huber March 10, 2023

@Robyn Lorenz   I'm just using the Smart Value {{now}} to add the current date (and time if you want) when the last comment is copied into the Most Recent Comment field.  (Size gives the total number of comments.)  Like this:

{{now.shortDate}} | {{issue.comments.last.author.displayName}} | {{issue.comments.last.body}} | {{issue.comments.size}}

Most Recent Comment.JPG

Like # people like this
Carl Palmquist March 13, 2023

Fantastic @Randall Huber !! :D Great work. Wonder if it could be possible to change the date format into my preferred YYYY-MM-DD or something similar.. but still fantastic!

Randall Huber March 13, 2023

@Carl Palmquisttry this: {{now.format("yyyy-MM-dd")}}

For more on Date smart  values, see:
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/

Robyn Lorenz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 13, 2023

@Randall Huber nice!  Thanks so much!  That worked wonders!  I just did the date / name on one line and the comments on another.

{
"fields": {
"Last Comment" :"{{now.shortDate}} {{issue.comments.last.author.displayName}} \n {{issue.comments.last.body}}"
}
}

Thanks again!!!

Like # people like this
Florian Demleitner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2023

The problem I have is that every time the comment contains an empty line or a line break, the automation is not performed and the comment is not transferred to the Last comment field.

For example when someone comments:

"Hello,

this is a comment."

Does anyone have a solution for this?An answer to this question would help me a lot :)

Like Paul Campbell likes this
Paul Campbell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2023

@Florian Demleitner I'm using this:

{
"fields": {
"Last Comment": "On: {{now.shortDate}}\n {{comment.author.displayName}} wrote:\n{{issue.comments.last.body}}"
}
}

And I just did a test with line breaks in it and I did not have the problem you mentioned

Florian Demleitner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2023

@Paul Campbell  Thank you very much now it works with your solution :). Something must have been wrong with my customfield.

Like Paul Campbell likes this
Christina Cuffari
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 9, 2023

Would some version of this configuration work in server/data center?

Like Lucile Cornet likes this
Lucile Cornet July 17, 2023

Hi all ! I was wondering the same question as Christina. Could this work on Jira DC or do you know an alternative ?

Like Christina Cuffari likes this
samarth gohel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 31, 2023

@Robyn Lorenz , worked perfectly, thank you so much

Screenshot 2023-07-31 225158.png

Christina Cuffari
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 31, 2023
TAGS
AUG Leaders

Atlassian Community Events