How to search for an issue's last comment via JQL in Jira Data Center

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Jira does not provide JQL functions to read the last comment on an issue. Automation for Jira can be used to supplement this functionality

Limitations

The solution described below may not scale well. The limitations include but not limited to:

  • Each time a comment is added, an automation rule runs which saves the comment into a custom field. This custom field and rule (by default), are applied to applied to all projects and all issues on the instance. Therefore, creating a comment may incur a performance penalty, as the comment action must be scheduled and processed by the automation queue system, then the issue update action actually executed. This issue update in itself may cause other listeners to fire. This may reduce the overall performance of the index, and automation systems

  • Comments are permitted to be large (up to 32K characters), and as they are added into the index by the rule, the index size may grow significantly. In general, it's better to have a smaller index, as index snapshot recovery time is proportional to it's size.

  • The rule will apply for new comments. There is no provision in this described solution to retroactively populate the last comment field on other issues. This may be possible to achieve by running a modified rule manually.

Environment

  • Jira Data Center

  • Automation for Jira

Solution

Step A - Add a custom field for the last comment

  1. Visit Jira Admin → Issues → Custom Fields

  2. Add a field "Text (Multi-Line), for all issue types, for all projects, with name "Last Comment"

    1. You may restrict the field's use as per your requirement

Step B - Add an automation rule to populate the last comment

  1. Visit Jira Admin → Automation Rules

  2. Click Create Rule

  3. On the New trigger screen, select Issue commented → Save

  4. Click New action

  5. Click Edit issue

  6. Find Last Comment in the field list, and check (tick) it

  7. In the textbox for Last Comment, enter the content 

    1 {{issue.comments.last.body}}
  8. Give your automation a name, for example, "Set Last Comment" and click Turn it On

Step C - Consume the last comment field

From now on, any new comment will be persisted to the Last Comment field. It can now be referenced in JQL: 

1 "Last Comment" ~ "Hello world!"

Updated on March 12, 2025

Still need help?

The Atlassian Community is here for you.