JMWE sum() array not summing array

Mike Leydet October 20, 2020

Edit: Solved. The custom field type was a short text field and the sum() function requires a numbers field or else it concatenates the values regardless of the value being numerical or alphabetical. 

 

 

What am I doing wrong?  Attempting to sum the value of the 10355 custom field found on all subtasks. 

1. Search using JQL function where current issue provides the issuekey for "Parent" issue. 

2. Return the value of the 10355 field (in this instance there are 2 values being returned, 3 and 2)

3. return field 10355 value of current issue (1)

4. sum array

the below returns: 003,21

{{
[
("Status not in (done,abandoned) AND 'Harvest Hours' IS NOT EMPTY AND parent =" + issue.fields.issuekey)|
searchIssues(fields = "customfield_10355") |
field("fields.customfield_10355"), issue.fields.customfield_10355
]|

sum()
}}


If I remove the "|sum()" from the code, It returns: 3,2,1

 

What is incorrect here?

2 answers

1 accepted

0 votes
Answer accepted
Mike Leydet October 20, 2020

Change the field type to number and use the following as an example:


{{

(

("Status not in (done,abandoned) AND 'Harvest Hours' IS NOT EMPTY AND parent =" + issue.fields.issuekey) |

searchIssues(fields = "customfield_10429") | field("fields.customfield_10429") | sum

)

+ issue.fields.customfield_10429

}}
2 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 20, 2020

For future reference: this code works with a text field:

{% set values = ("Status not in (done,abandoned) AND 'Harvest Hours' IS NOT EMPTY AND parent =" + issue.fields.issuekey) | 
searchIssues(fields = "customfield_10355") | field("fields.customfield_10355") %}
{% set total = issue.fields.customfield_10355 | int %}
{% for val in values %}
{% set total = total + (val | int) %}
{% endfor %}
{{total}}
Maggie Gu March 31, 2021

Thank you so much @David Fischer !! Your answer resolved my problem.

Suggest an answer

Log in or Sign up to answer