Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Count comments that match text

Randy Simes August 16, 2024

I'm trying to get a count of the comments that match specific text using a lookup. My attempts have gotten me either the total number of comments or 0/blank.


{{#lookupIssues}} - {{key}}: {{#=}} {{#comments}} {{#if(equals(body.match("<Match text>").size, 1))}} 1 {{/}} {{/}} {{/}} times {{/lookupIssues}}

I'd like to get this into a single email report that shows the key and the number of comments that match. 

Key 1 - 5
Key 2 - 1
Key 3 - 2

The lookupIssues matches on this comment so the result should never be 0.

 

1 answer

1 accepted

2 votes
Answer accepted
Bill Sheboy
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.
August 16, 2024

Hi @Randy Simes 

First, the match() function could have problems with any embedded line breaks / newlines on the match.  To address that you may use replace("\n", " ") before the match() call.

Next, as you only want a count, the iteration over comments and math expression are not needed, as the match() will produce a list that can be counted with size.

Putting those together, please try this:

{{#lookupIssues}}
{{key}} -- {{comments.body.replace("\n"," ").match(".*(match text).*").size|0}}
{{/}}

If your text includes reserved characters, you may need to add escaping.  Please see the documentation for the match() functions use of regular expressions to learn more: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

This should produce a count of 1 for each matching comment.  If instead you want the total number of matches, including multiple per comment, the expression approach must be changed.

Kind regards,
Bill

Randy Simes August 16, 2024

That worked (had to add one { before comments). I was missing the trailing information with .* - thanks Bill!

Like Bill Sheboy likes this
Bill Sheboy
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.
August 16, 2024

Thanks, and I fixed my post. 

I should have tested that one and not just typed it in  :^)

Kunal Kumar February 7, 2025

Hey @Bill

I have a requirement where i want to count the total number of comments which contain a certain expression and publish the result into a field in JIRA. Can you please help me with the match() construct for the same. 

Bill Sheboy
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.
February 7, 2025

Hi @Kunal Kumar 

First, this is a very old thread, and so it helps to create a new question.  That ensures the maximum number of people see it to offer suggestions...rather than trying to add to the old thread.

I found your new question, adding some suggestions here:

https://community.atlassian.com/t5/Jira-questions/Count-all-the-comments-on-a-story-that-have-a-matching/qaq-p/2938739

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events