JMWE error "expected a number but got" on a sum() event-based calculation.
Asked by Sally Wheeler:

I am new to using JMWE and I probably have the syntax incorrect but I cannot figure out what is wrong.

I have an issue type named shipment in which a number field is entered with the number of samples in that shipment.

This issue type is under an epic.

I would like a total number of samples field to be shown on the epic view screen where it is continually updated every time the number of samples field is updated in any shipment for the epic.

This is what I did. But the field still says None. I even went to a shipment and switched a number and switched it back to hopefully trigger the calculation and still nothing. Can you help to clarify what I am misunderstanding? The error it states: "expected a number but got: \| sum({issue.fields.customfield_10083})"

![image.png](/t5/image/serverpage/image-id/206006i077B9A6C522F8678/image-size/large?v=v2&px=999 "image.png")


Answers:
author: David Fischer
body: Hi [@Sally Wheeler](/t5/user/viewprofilepage/user-id/4930648) ,

the correct syntax for the value would be:

```
{{targetIssue | stories("customfield_10083") | field("fields.customfield_10083") | sum }}
```

* *targetIssue* represents the target issue (the parent Epic of the current issue)
* *\| stories("customfield_10083")* returns all Stories of that Epic, returning only the customfield_10083 custom field (for efficiency)
* *\| field("fields.customfield_10083")* returns an array of the value of the customfield_10083 field for each Story
* *\| sum* sums up the values in the array

comments: author: Sally Wheeler
body: Thank you. [@David Fischer](/t5/user/viewprofilepage/user-id/538255) I really appreciate you breaking down the syntax. I am new to using the language and am struggling. Even the documentation that is provided does not breakdown when you have to work with different issue levels.

It is now giving the error "NaN". I do have the total field configured as a number as well as the fields that we are pulling. Do you know what could be causing this?


author: Sally Wheeler
body: [@David Fischer](/t5/user/viewprofilepage/user-id/538255) I also have different stories of which this field is not present in. Is there a way to specify the story? I feel like this might be the issue.


author: Sally Wheeler
body: ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/206089i5927903FBFC8FD98/image-size/large?v=v2&px=999 "image.png")

I would like this to run on "Incoming Shipment"


author: David Fischer
body: [@Sally Wheeler](/t5/user/viewprofilepage/user-id/4930648) that is indeed the reason. We have pushed a small improvement to ignore null values in the *sum* filter which should fix your problem.


author: Sally Wheeler
body: [@David Fischer](/t5/user/viewprofilepage/user-id/538255) Is there anything I can do now to get this to work prior to waiting on the fix? Can I specifically call the issue type name?


author: David Fischer
body: Did you try again after my last comment?


author: Sally Wheeler
body: Oh!! It works! Thank you!! [@David Fischer](/t5/user/viewprofilepage/user-id/538255)


author: Sally Wheeler
body: Can you tell me the syntax for if I wanted to take this one step further and only grab field for a certain label? [@David Fischer](/t5/user/viewprofilepage/user-id/538255)


author: David Fischer
body: Hi [@Sally Wheeler](/t5/user/viewprofilepage/user-id/4930648) ,

that's a little more complicated. I assume you mean that you want to sum the value of the field only on Stories of the parent Epic that have a certain Label, correct?

In that case, the script would be something like:

```
{% set total = 0 %}
{% for story in targetIssue | stories("customfield_10083,labels") %}
  {% if story.fields.labels.includes("mylabel") %}
    {% set total = total + story.fields.customfield_10083 %}
  {% endif %}
{% endfor %}
{{total}}
```


author: Sally Wheeler
body: Hi [@David Fischer](/t5/user/viewprofilepage/user-id/538255) I apologize, I should have elaborated. Yes in general. It is actually value of the field on a subtask of a story to be reported out on the story.

The story level is called Invoicing Matrix. The subtask is called Milestone. (All still under the Epic, but I don't think we need to go that far since I am reporting out in the story level)

I am building out an invoicing workflow where there are Milestones (has its own workflow) that are captured in the Invoicing Matrix (has a broad stroke workflow).

What I am trying to create is a custom log of the Milestones. Where monthly, the number of Milestone per month is invoiced and stored in a field "#accrued" and "date accrued". I would like to create a log of when this field is populated and potential clear the field to be available for a new entry. In the log, I would like to also sum the #accrued of the milestone over time as "total accrued".

I was thinking of using your solution above for the last part but I do not even know if the log is feasible. And if it is not feasible, then I need to find a way to capture a repeated use of a "Milestone". Maybe a circular point in the workflow, where I use a post function in the transition to clear the field (if possible). But I would still need a way to capture the history. If you have any ideas, it would be appreciated.


author: David Fischer
body: Hi Sally,

I'm not sure I fully understood your requirements, and they seem fairly sophisticated. I'm sure it would be doable with JMWE but you might need to get help from a Solution Partner with JMWE Cloud expertise.

You might also want to have a look at JMWE's Event-based actions (to automatically do calculations when a field is modified) and Scheduled Actions (if you want to automate monthly invoices.


Tags: cloud