Forums

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

Syntax question #if + #count

JEFFREY SCHNEIDER
May 28, 2026

I have a simple automation:

Trigger is scheduled daily.

I have a broad lookup for issues updated yesterday.

Lastly I have an email with 2 tables of issues in the lookup, but I'm filtering with the #if function for each table. (Table specifics removed since it works as expected).

Table 1: {{#lookupIssues}}{{#if(equals(customfield_12345.value, "Yes"))}}
Table 2: {{#lookupIssues}}{{#if(equals(customfield_12345.value, "No"))}}

The tables/list work perfectly, however I'm running into a challenge with combining the #if and a #count by following the Automation documentation (as best as I could...)

Total: {{#lookupIssues}}{{#if(equals(customfield_12345.value, "Yes"))}}{{#=}}{{count}}+1{{/}}{{/}}{{/}}

 What I end up with is "11111" rather than "5"

3 answers

1 accepted

0 votes
Answer accepted
Trudy Claspill
Community Champion
May 28, 2026

Hello  @JEFFREY SCHNEIDER 

Gemini suggested the following.

 

{{#=}}0{{#lookupIssues}}{{#if(fieldName.equals("specificValue"))}}+1{{/}}{{/}}{{/}}
Breakdown of the Syntax:
  • {{#=}} ... {{/}}: This wraps the calculation in a math expression.
  • 0: The starting value for your counter.
  • {{#lookupIssues}} ... {{/}}: Iterates through every issue found by the "Lookup Issues" action.
  • {{#if(fieldName.equals("specificValue"))}}+1{{/}}: For each issue in the list, if the specified field matches your value, it adds 1 to the total.

 

I tested it with this, and got the results I expected:

{{#=}}0{{#lookupIssues}}{{#if(priority.name.equals("Medium"))}}+1{{/}}{{/}}{{/}}

 

0 votes
Darryl Lee
Community Champion
May 28, 2026

Hi  - I'm sure  's answer is right, but I was curious about why yours gave what it did.

Total: {{#lookupIssues}}{{#if(equals(customfield_12345.value, "Yes"))}}{{#=}}{{count}}+1{{/}}{{/}}{{/}}

I believe the reason is that {{count}} is not a valid Smart Value, and so Automation is interpreting it as an empty string, and then interprets the +1 as "concatenate 1" (instead of add).

I wonder if creating a variable named count, and setting it to 0 (zero) would allow your formula to work as expected.

0 votes
Darryl Lee
Community Champion
May 28, 2026

Hi @JEFFREY SCHNEIDER - I'm sure @Trudy Claspill 's answer is right, but I was curious about why yours gave what it did.

Total: {{#lookupIssues}}{{#if(equals(customfield_12345.value, "Yes"))}}{{#=}}{{count}}+1{{/}}{{/}}{{/}}

I believe the reason is that {{count}} is not a valid Smart Value, and so Automation is interpreting it as an empty string, and then interprets the +1 as "concatenate 1" (instead of add).

I wonder if creating a variable named count, and setting it to 0 (zero) would allow your formula to work as expected.

Darryl Lee
Community Champion
May 28, 2026

Ah yeah, no, setting {{count}} = 0 didn't help, and I could only get it to work when I wrapped the whole thing in a math expression, like Trudy did:

Total: {{#=}}0{{#lookupIssues}}{{#if(equals(customfield_10151.value, "google-112233"))}}+1{{/}}{{/}}{{/}}

OH wait. Right. The problem is that maybe you never actually increment the {{count}} Smart Value.

So in your rule {{count}} was evaluating to 0 every time, and 0+1 = 1, 5 times.

I'm pretty sure Jira Automation does not have a way to modify variables within list functions. Isn't that right, @Bill Sheboy ?

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 Champions.
May 29, 2026

Hi @Darryl Lee 

Yes, and yes...

{{count}} is not a defined smart value.  For an inline-format, list iterator, the sum function may be used on a number value and the size function may be used over any list values.

And for long-format, list iterator, such as {{#lookupIssues}} ... {{/}}, the only data accessible is from the iterator scope (and lower).  Thus, even if a variable was created named count it would not be accessible inside of the expression.  This is a long-standing, known limitation (which I hypothesize is one of the many problems caused by how the list closures are formed in the automation engine).

 

Thus, there are at least two solutions to the original question:

a) The one @Trudy Claspill shows with long-format list iteration, list filtering, and math expressions to count one for each item...including suitable default handling

2) Inline-iteration over the value, flattened into a single list (to reduce the nested-lists), a match() with a regular expression to filter, and finally using size for the count:

{{lookupIssues.customfield_12345.value.flatten.match("(Yes)").size|0}}

 

Kind regards,
Bill

Like Trudy Claspill likes this
Darryl Lee
Community Champion
May 29, 2026
{{lookupIssues.customfield_12345.value.flatten.match("(Yes)").size|0}}

@Bill Sheboy NICE. I was thinking about how to use size and thought I'd have to do the split + join trick, but flatten + match is far more elegant.

Ah, this takes me back to the days of Perl, where one of the chief tenets was (is?!TIMTOWTDI. :-}

Like # people like this
Trudy Claspill
Community Champion
May 29, 2026

I saw the size option mention in the Gemini response too. I just didn't try that one out. 😄

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events