Create a calculated custom field in an epic that sums the value of a custom field of linked issues?

gayane.khayiguian
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 22, 2020

Hi Everyone, 

We have the Addon JIRA MISC CUSTOM FIELD 

https://innovalog.atlassian.net/wiki/spaces/JMCF/overview?homepageId=141891457

I would like to create a calculated field in an epic that would sum the values of a number custom field filtered on the current linked issues of the epic. 

I am pretty sure this is possible to do it with the addon but i am struggling to write the right script, as I have too few knowledge on Groovy script. Could anyone help me with a code ? 

 

Here is what i would like : 

Epic

Calculated custom field = Sum of values of linked issues Custom field 1

Epic Linked issues

Issue 1

Value Custom field 1

Issue 2

Value Custom field 1

Issue 3

Value Custom field 1

 

Thank you so much for your help! 

2 answers

0 votes
Arne Becher May 24, 2021

Hi Like,

I have a basic question about the examples shown here.

Is there somewhere a general description of all possible programming commands for automations, preferably with examples?

Thanks
Arne

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.
May 24, 2021

Hi @Arne Becher ,

you mean beyond the JMCF documentation? The documentation already provides information about the Groovy language, with a tutorial and a lot of examples.

Arne Becher May 25, 2021

Hi Like,

thank you very much.

However, I meant commands for Jira Automations to be used in general.

Also I oversaw that the thread above is related to jira server and an add-on for that. Unfortunately I use jira cloud

0 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.
July 22, 2020

Hi,

what is the link between the Epic and the issues from which to sum the custom field? Are they the issues that belong to the Epic? If so, you can use this:

issue.stories.sum {it.get("customfield_12345")?:0}

If they are issues linked to the Epic through issue links, you can do something like:

issue.getLinkedIssues("link type direction").sum {it.get("customfield_12345")?:0}
gayane.khayiguian
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 22, 2020

Hi David, Thanks for your answer! 

I tried and the script returns no error but even though my fields have values it still returns "null"

I created 3 tasks and completed values in the custom number field i want to sum + have added the epic link but it doesn't seem to sum the value in the calculated field in the epic...

Could it be because of the "link type direction"? 

 

Thanks again for your precious help! 

 

image.png

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.
July 22, 2020

If you have added the Epic Link on the tasks, that means the task belong to the Epic. You therefore need to use the first script I provided. 

Gunti_Reddy February 28, 2021

HI, 

Please provide script to add sum of one or more custom fields from Stories to EPic. 

 

Here is what i would like : 

Epic

Calculated custom field = Sum of values of linked issues Custom field 1 and Custom field 2

Epic Linked issues

Issue 1

Value Custom field 1

Value Custom field 2

Issue 2 

Value Custom field 1

Value Custom field 2

 

Thanks,

Gunti

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.
March 1, 2021

Hi @Gunti_Reddy ,

try this:

issue.stories.sum {
it.get("custom field 1")?:0 + it.get("custom field 2")?:0
}
Gunti_Reddy March 2, 2021

Hi David, Thanks for your response, 

 

getting below error, but it works when i add one custom field for sum.

 

Message:
groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.Integer#plus.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
 [class java.lang.Character]
 [class java.lang.String]
 [class java.lang.Number]


 Below line works for one custom field sum.

issue.stories.sum {it.get("customfield_15462")?:0} 

 

Thanks,

Gunti

Gunti_Reddy March 2, 2021

I made small changes and working for two custom fields sum  as well.

 

issue.stories.sum {it.get("customfield_15460")?:0} + issue.stories.sum {it.get("customfield_15462")?:0}

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.
March 2, 2021

Yes, sorry, I had forgotten to add parentheses:

issue.stories.sum {
(it.get("custom field 1")?:0) + (it.get("custom field 2")?:0)
}

Suggest an answer

Log in or Sign up to answer