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

Count all the comments on a story that have a matching expression in them

Kunal Kumar February 7, 2025

I am looking to create an automation rule which counts all the comments on a story that have a matching expression in them and input the total number into a field in JIRA .Can anybody help me with that? 

1 answer

0 votes
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 

For a question like this, context is important for the community to help.  Please post the following:

* an image of your complete automation rule in a single image,
* images of any relevant actions / conditions / branches,
* an image of the audit log details showing the rule execution, and
* explain what is not working as expected and why you believe that to be the case.

Until we see those...

Have you tried using a regular expression with the match() function to do this? https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

With that approach, the number of matches could be counted using the list size function: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#list.size

Kind regards,
Bill

Kunal Kumar February 10, 2025

Hello Bill , 

 

Unfortunately I cannot post SS of my rule due to org restrictions. However I'll try to explain what I'm doing. 

 

In the automation rule,  im having an action block where I'm updating a field with the following expression .

 

{{comments.body.replace("[\r\n]","").match("(?i).*(evaluate).*").size|0}}

 

This is giving me the desired result - no of comments with evaluate expression .

 

However,  i wish to implement an additional check where it should only consider comments added by a particular individual along with the matching expression

 

Can yoh help me figure out how I can achieve that ?

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 11, 2025

No worries; I completely understand the challenge in some workplaces of posting rule images.

 

Next, I recommend not using regular expression syntax for flags (e.g. "(?i)") in automation rules as it is not documented if that does / does not work with Atlassian's implementation of regex.  That will save time debugging regex.

Instead, try forcing the comment body to a known case before the match, such as with the toLowerCase() function.

 

Back to your scenario, you could use smart value, list filtering to extract the comments (or an indicator) that match, storing the results with Create Variable, and then evaluate the variable for the results.

For example:

  • action: create variable
    • name: varMatchingCommentBodies
    • value:
{{#issue.comments}}{{#if(and(equals(author.displayName, "Bill"), body.replaceAll("[\r\n]","").toLowerCase().match("(evaluate)").size.gt(0)
))}}{{body}}~~{{/}}{{/}}

That will iterate over the comments, testing the author and body to filter them, and return the body when matched, with a delimiter of "~~" between records.

  • use these for the list of comments or the count
    • {{varMatchingCommentBodies.substringBeforeLast("~~").split("~~")}}
    • {{varMatchingCommentBodies.substringBeforeLast("~~").split("~~").size}}

 

Please adjust / test that expression as I just typed it in without testing.

 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events