Calculate sum of custom number field from all epics to their Initiative

Maggie Gu March 31, 2021

Hi Guys,

Does anyone know how to calculate sum of a custom number field from all epics to their initative? I tried ScriptRunner and JMWE. JMWE seems more simple. But I cannot get the right value. It always return NAN.

 

Here is the case:

We use advanced roadpmap in our jira cloud. Use the Initiative and Epic types. Added a custom number field: Score. Want to calculate sum of Score in all epics automaticlly.

- TIS-1 Initiative issue:  (Score: <Empty>)

|----TIS-2 Epics issue No.1  (Score: 11)

|----TIS-3 Epics issue No.2  (Score: 22)

|----TIS-4 Epics issue No.3  (Score: 33)

|----TIS-5 Epics issue No.4  (Score: 44)

Use Event-based Actions in JMWE:

Current issue: TIS-2

Target issue: TIS-1

{{issue | initiative()|membersOfInitiative("Score")|sum("Score")}}

Always return: NaN

 

BTW: If you have any suggestion by ScriptRunner, please don't hesitate to comment!!

Thanks in advance!

1 answer

1 accepted

1 vote
Answer accepted
Maggie Gu March 31, 2021

Resolved my question by https://community.atlassian.com/t5/Jira-Software-questions/JMWE-sum-array-not-summing-array/qaq-p/1511608#U1652205 

 

Here is what I did:

  1. Use "Event-based Action" ;
  2.  Add "Set field value" Post-functions;
  3. Choose "Parent issue of the current issue in the Portfolio hierarchy" as "Target Issue"
  4. Field "Score" and the following code in value.

         (customfield_10047 is the ID of "Score", customfield_10018 is the ID of "Parent Link")

{% set values = ("'Parent Link' = " + issue.fields.customfield_10018.data.key) | searchIssues(fields = "customfield_10047") | field("fields.customfield_10047") %}
{% set total = 0 | int %}
{% for val in values %}
{% set total = total + (val | int) %}
{% endfor %}
{{total}}
 

Suggest an answer

Log in or Sign up to answer