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.
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
That worked (had to add one { before comments). I was missing the trailing information with .* - thanks Bill!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, and I fixed my post.
I should have tested that one and not just typed it in :^)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.