We're setting up a rule and running into errors. We've added logging to the rule but we're surprised by the results - we're wondering:
How does the following log result in an output of "true, true"? We would expect to log nothing or false, but definitely not true
{{#if(not(lookupIssues.Create/Update Automated Tests?.value.startsWith("N")))}} {{lookupIssues.Create/Update Automated Tests?.value.startsWith("N")}} {{/}}
Edited to add tl;dr - here's the answer that I think Lana was looking for when she clarified:
If I want to get the sum of “StoryPoints” for all lookup issues where “Create/Update Automated Tests?” is set to “Needed for Release”
{{#=}}0{{#lookupIssues}}
{{#if(not(Create/Update Automated Tests?.value.startsWith("N")))}} + {{Story points}}{{/}}{{/}}{{/}}
Although now that I look at that, I think that would *exclude* issues "Needed For Release" since that option starts with "N". For your exact example, I think you would want:
{{#=}}0{{#lookupIssues}}
{{#if(equals(Create/Update Automated Tests?.value,"Needed for Release"))}} + {{Story points}}{{/}}{{/}}{{/}}
Everything below is the long journey it took to get there. Once again, thanks to @Bill Sheboy for the assist.
Hi @Lana Laureano --
Well, for one thing, I believe Lookup Issues returns {{lookupIssues}} as a list, so I think that what you've written checks that field for every issue that was looked up, if it is in fact working at all.
(Because I'm not sure what the expected behavior would be for the startsWith function when you are looking at a list instead of a single string.)
If you're confident that only one issue will ever be returned from your Lookup Issues action, then you might try adding .first to limit checking to a single issue's field value:
{{#if(not(lookupIssues.first.Create/Update Automated Tests?.value.startsWith("N")))}}
{{lookupIssues.first.Create/Update Automated Tests?.value.startsWith("N")}} {{/}}
The other suggestion I'd have is to put the field name in quotation marks, like:
{{#if(not(lookupIssues.first."Create/Update Automated Tests?".value.startsWith("N")))}}
{{lookupIssues.first."Create/Update Automated Tests?".value.startsWith("N")}} {{/}}
I can't find the post, but @Bill Sheboy discovered the quoting thing a while back. Haven't done any testing recently to see if it's actually still required.
There is the doc for your reference
https://support.atlassian.com/cloud-automation/docs/smart-values-in-jira-automation/
Thanks,
Joy <Automation for Jira>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The more general question I haven’t been able to understand is how exactly conditional logic against lists is working. If I want to get the sum of “StoryPoints” for all lookup issues where “Create/Update Automated Tests?” is set to “Needed for Release”, then what kind of function would I need to write? It seems like adding that check as the if block still results in all the lookup issues existing inside of it.
This is also what I was intending to highlight above - my understanding was that I could filter down the lookupIssues by checking against a condition, but I found that checking against the same condition inside the if block, nothing was filtered out at all.
I would really like to do this without re-getting the lookupIssues with a new JQL query because I’m still using these lookupIssues as part of my field edit as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's a great article on Filtering smart value lists.
Hmm if you're looking to sum up Story Points up only if ... I wonder if something this would work:
Before the Lookup, set a variable {{NeededForReleaseStoryPoints}} = 0
And then after the lookup:
{{#lookupIssues}}
{{#if(not("Create/Update Automated Tests?".value.startsWith("N")))}}{{#=}}
{{NeededForReleaseStoryPoints}} + {{Story points}}{{/}}
{{/}}
I need to test this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Side question: Is "Create/Update Automated Tests?" a text field?
I would expect that field to be a required single-select (Yes or No) or a single checkbox. Having to do .startsWith("N") is a little... odd.
:-}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's not a text field, it's a select field with the options Needed, Not Needed, Needed for Release
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Huh, interesting. So what are the options you ARE trying to match for?
BTW my code above doesn't work, but I think I'm getting closer. Update in a bit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Bill Sheboy and @Sam Harding for the life of me I cannot figure out why none of these work. Wondering if you have any thoughts.
The goal is eventually to take the result of FilteredStoryPoints and do a .split and .sum.
(Where I have a few issues where Single Select="Test")
FilteredStoryPoints: {{#lookupIssues}}{{#if(Single Select.value.startsWith("T"))}}{{Story Points}},{{/}}{{/}}
FilteredStoryPoints: {{#lookupIssues}}{{#if(Single Select.startsWith("T"))}}{{Story Points}},{{/}}{{/}}
FilteredStoryPoints: {{#lookupIssues}}{{#if(equals(Single Select, "Test"))}}{{Story Points}},{{/}}{{/}}
While this returns all the Story Points and all the Single Selects for each issue:
AllStoryPoints: {{#lookupIssues}}{{Story Points}},{{/}}
AllSelects: {{#lookupIssues}}{{Single Select.value}},{{/}}
AllStoryPoints: 7.0,2.0,1.0,
AllSelects: Test,,Test,FilteredStoryPoints:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure why but I tried to respond and my message got blocked with "You may have recently posted the same thing elsewhere on the community. Update your text, or wait before reposting."
Hope this doesn't get me in trouble, but I'm attaching an image of what I typed up - I don't know how else to respond, or how long I'd have to wait before reposting. Thanks for all your help with this @Darryl Lee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lana Laureano - yeah, it's really weird. I can't get any of my filters to work either.
That's interesting that the Manual QA points thing works, although I'm thinking that if QAPoints - Manual actually evaluates to null, then wouldn't that evaluate to... null, which might be interpreted to zero?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, all!
It is possible to filter and sum...but you cannot do that with the built-in lookup issues functions. Instead combine the math operators with filtering and handle the empty cases. For example,
{{#=}} 0 {{#lookupIssues}}{{#if(some filter expression)}} + {{some field}}{{/}}{{/}}
The leading 0 and the placement of the + {{some field}} are key to prevent any null values collapsing the entire result to null, or leading to an error.
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.
Thanks @Bill Sheboy - this would totally be helpful... if I could get the filters to work at all!
As mentioned, I haven't even gotten to the part where I try to add the numbers together. I can't get the numbers to show up at all with these attempts:
FilteredStoryPoints: {{#lookupIssues}}{{#if(Single Select.value.startsWith("T"))}}{{Story Points}},{{/}}{{/}}
FilteredStoryPoints: {{#lookupIssues}}{{#if(Single Select.startsWith("T"))}}{{Story Points}},{{/}}{{/}}
FilteredStoryPoints: {{#lookupIssues}}{{#if(equals(Single Select, "Test"))}}{{Story Points}},{{/}}{{/}}
I've even tried customfield_10079.value in case the space in the field name was messing things up, as we know it sometimes does. And... nada:
FilteredStoryPoints: {{#=}} 0 {{#lookupIssues}}{{#if(equals(customfield_10079.value,"Test"))}} + {{Story Points}}{{/}}{{/}}{{/}}
It's the darndest thing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Darryl Lee
I wonder if this is either a field type/value or a smart value typo thing...I tried this with another single select, custom field's value and it worked for me in Jira Cloud...
total count: {{#=}}0{{#lookupIssues}}{{#if(Current environment.value.startsWith("T"))}} + 1{{/}}{{/}}{{/}}
and total story points: {{#=}}0{{#lookupIssues}}{{#if(Current environment.value.startsWith("T"))}} + {{Story points|0}}{{/}}{{/}}{{/}}
Of note: I added null handling and changed the capitalization of the "Story point" smart value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AUGH. I figured out my problem. My "Single Select" field was misnamed (I was reusing it from some other thing) - it was actually a Multi Select, so I guess it was returning a list. Bah.
I created a new actual "Single Select" field and it worked exactly as you described @Bill Sheboy!
SO, @Lana Laureano as long as "Create/Update Automated Tests?" is a what Jira calls a "Select List (single choice)" field, then this should work for you:
{{#=}}0{{#lookupIssues}}
{{#if(not(Create/Update Automated Tests?.value.startsWith("N")))}} + {{Story points}}{{/}}{{/}}{{/}}
(I even tested the field name without quotes, and it works!)
(Hrm, I wonder if there's a way to check if any options of a multi-select field start with N.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Re: checking a multi-select field. It doesn't look like you can iterate a list inside of another list iteration:
{{#=}}0{{#lookupIssues}}{{#Not Really Single Select}}{{#if(value.startsWith("N"))}} + {{Story Points}}{{/}}{{/}}{{/}}{{/}}
I thought about using join and then looking for .match(".*,T.*"), but that would never match if "Needed" was the first option in the multi-select.
But this is all theoretical, since I'm pretty sure your Lana's field is a single select.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, and...it is possible to nest iterators but apparently not for the same list (.i.e. same lookup issues result set). A child list (e.g. Sprint, multi-select field, etc.) can be walked inside.
Darryl, for your extended use-case, I would instead suggest pre-filtering to a created variable to create a delimited list of key|value pairs, where "key" is the list of multi-select field values, and then use match and text functions to get at the "value". This would circumvent the problem of many smart values cannot be used as function parameters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.