Extracting the Last Five Comments from Jira Issues Using Automations

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

Summary

This article provides a detailed guide on how to use Jira Automation to extract the last X comments from an issue in Jira. This is particularly useful for project managers and team leads who need to stay updated on issue progress and team discussions.

Diagnosis

To diagnose if this is the solution you need, ask the following questions:

  • Do you frequently need to stay updated on the most recent discussions on a Jira issue?

  • Do you find it time-consuming to manually find and read through the latest comments?

  • Are you looking for a way to automate this process and receive the latest comments directly in your email?

Cause

Jira users often need to extract a certain number of recent comments from a list of issues, but there is no direct way to limit or filter a list using Jira smart values. You can access the first or last comment, or use .get() and .getFromEnd() to access a specific comment in the list, but extracting a specific number of comments requires a different approach.

Solution

To solve this issue, we will use Jira Automation. This involves creating a variable to store the comments in a text string and then using a regular expression to select the first five items. Here's how you can do it:

Step 1: Create a variable to store the consolidated list and their 0-based index

  • Name: varLookupData

  • Smart value: Create a text string, delimited by ";index:" at the beginning of each issue.

1 {{#issue.comments.reverse}};index:{{index}} - {{author.displayName}} {{created.convertToTimeZone("Asia/Kolkata").format("dd-MM-yy hh:mm a")}} {{body}} {{/}}

Step 2: Log the results (or whatever you need) with the results of the first 5 items

1 {{varLookupData.split(";index").match(":((0|[1-5]) .*)").substringAfter(" - ")}}

This will split the text string on ";index" and create a new list. The match() function will then find only items beginning with ":0" through ":19". The final substringAfter removes the index prefix information, leaving only the summary and author.

Automation substringAfter image

However, this will output the final list as a string, and may not parse for HTML. To build your HTML, you can use the `list.getFromEnd(index)` function. Here's an example:

1 2 3 4 5 <tr bgcolor="#ffffff"> <td>{{issue.comments.reverse.getFromEnd(0).author.displayName}}</td> <td>{{issue.comments.reverse.getFromEnd(0).created.convertToTimeZone("Asia/Kolkata").format("dd-MM-yy hh:mm a")}}</td> <td>{{issue.comments.reverse.getFromEnd(0).body}}</td> </tr>

By following these steps, you can automate the process of extracting the last five comments from a list of Jira issues and sending them via email. This will save you valuable time and ensure you stay updated on the latest issue progress and team discussions.

For more details on Jira Smart Values, please refer to the official Jira documentation: https://support.atlassian.com/jira-software-cloud/docs/smart-values-general/.

Remember, automation can save you time and reduce manual errors. Start using Jira Automation today and streamline your project management process.

Updated on June 5, 2024

Still need help?

The Atlassian Community is here for you.