Forums

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

A4j .size returning 1 for an empty list

Dave Furlani
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.
March 19, 2024

I'm having trouble getting size to count to zero when there is nothing in a list.

Through some other funky use of smart values, I have built a variable (one per squad using the same syntax) that holds the sprints for each ticket delivered by a squad for a specific Epic. The string held in teamSprintsTESTamps looks like this:

Amps Sprint 7@Amps Sprint 7@Amps Sprint 5@Amps Sprint 6@Amps Sprint 7@Amps Sprint 6@Amps Sprint 6@Amps Sprint 5@Amps Sprint 7@Amps Sprint 6@Amps Sprint 7@Amps Sprint 5@Amps Sprint 4@Amps Sprint 7@

Using the following, the result given is "Amps: 4" (correct)

Amps: {{teamSprintsTESTamps.substringBeforeLast("@").split("@").distinct.size|0}}

For another team that only had one task in the Epic that they delivered in one sprint, the string held in teamSprintsTESTheat looks like this:

Heat Sprint 7@

And the result returned is "Heat: 1", which is also correct:

However for the teams that did not contribute to the specific epic, the result returned by .size is 1 (incorrect).

For the team that were not part of the delivery of Epic X, the following code: 

Bigbus: {{teamSprintsTESTbigbus.substringBeforeLast("@").split("@").distinct.size|0}}
A. #{{teamSprintsTESTbigbus}}#
B. {{teamSprintsTESTbigbus.substringBeforeLast("@")}}
C. {{teamSprintsTESTbigbus.substringBeforeLast("@").split("@")}}
D. {{teamSprintsTESTbigbus.substringBeforeLast("@").split("@").distinct}}
E. {{teamSprintsTESTbigbus.substringBeforeLast("@").split("@").distinct.size}}

Returns the following output (to prove to you there's no value in that variable:

Bigbus: 1
A. ##
B.
C.
D.
E. 1

Is there a way to get the correct result of 4 for Amps and get the correct result of 0 for Bigbus?

*Squad names have been changed to protect the innocent

1 answer

1 accepted

0 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.
March 20, 2024

Hi @Dave Furlani 

What is in the variable teamSprintsTESTbigbus when they did not contribute to the specific epic: an empty string, just a trailing @ symbol, something else?

Knowing that may help to use conditional logic to handle the 0 and non-zero cases.

Kind regards,
Bill

Dave Furlani
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.
March 20, 2024

Looks like an empty string:

A. #{{teamSprintsTESTbigbus}}#

Output

A. ## 

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.
March 20, 2024

Thanks; that looks like it is null.

Are you trying to create one smart value expression that works for all cases, or are you open to a couple of them?  (e.g., use conditional logic to handle the 0 case separately from the others)

Dave Furlani
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.
March 20, 2024

Thanks @Bill Sheboy

It's hard to say without seeing the outcome. If you have the time, please hit me with both and I'll test to see which best suits the use case
 

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.
March 21, 2024

FYI for stuff like this, you really do need to experiment.  There is a bit of exploring required as not everything for rule behavior is documented to know what will / will not work...particularly when fields could be null.  Anyways...

Assuming the variable is empty when there are no sprints, and it ALWAYS ends in an At-sign @ when there are sprints, a conditional block may be used, checking the length of the variable.

{{if(teamSprintsTESTbigbus.length().gt(0), teamSprintsTESTbigbus.substringBeforeLast("@").split("@").size, 0)}}

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

Like Dave Furlani likes this
Dave Furlani
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.
March 21, 2024

Good call, The variable will always contain an @ delimiter IF there is any data. Checking length or the existence of the @ delimiter should work.

That worked. Thanks @Bill Sheboy 

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events