Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,550
Community Members
 
Community Events
184
Community Groups

Sum of a custom field value to another custom field

Can you please help me with script of the below use-case –  

For a sub-story which is linked to a story.

I want to calculate the sum of the values of a custom field (Technical Points) belonging to issuetype – Sub-story. Further, I want that value to be placed in another custom field (Aggregate Technical Points) belonging to a custom issuetype - story. Attached screenshots display different

Attached screenshots display different issuetypes (Story and Sub-story) that we are using, just to avoid confusions.

Please help me with the script of the above use-case.Screen Shot 08-22-17 at 05.48 PM.PNG

1 answer

1 vote
Joshua Yamdogo _ Adaptavist
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.
Aug 28, 2017

Hi Swapnil,

I understand your use-case and I think I have a script that almost accomplishes this, but could you clarify?

Do you want the sum of ALL issues in the project that have an issue type of "Sub-story", regardless if they are connected to the same Story?

  • Example: Calculate the sum of 'Technical Points' of all issues that have an issue-type of "Sub-story" in the entire project.

Or

Do you want the sum of all connected "Sub-story" issues for each Story?

  • Example: A Story has 5 sub-stories. Calculate the sum of the 'Technical Points' of the 5 sub-story issues and display on the Story.

Hi Joshua,

 

Thank you for looking into this.

I would require the second example - 

"Do you want the sum of all connected "Sub-story" issues for each Story?

  • Example: A Story has 5 sub-stories. Calculate the sum of the 'Technical Points' of the 5 sub-story issues and display on the Story."

 

Thanks again for your help.

Best Regards,

Swapnil Tiwari

Joshua Yamdogo _ Adaptavist
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.
Aug 31, 2017

Hi Swapnil,

I created the following script to be used in a scripted field. It gets all of the links from the Story and checks to see if the are of type "Sub-story". If there are "Sub-story" linked issues, it will get the custom field value from "Technical Points" on each issue. It will return the sum of all of the Sub-story issues linked to the Story.

import com.atlassian.jira.component.ComponentAccessor

if (issue.getIssueType().name == "Story") { // only calculate this for Story Issue Types
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def pointSum = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> // go through all issues linked off of the Story
def linkedIssue = issueLink.getDestinationObject()
if (linkedIssue.getIssueType().name == "Sub-story") {
def technicalPointsField = customFieldManager.getCustomFieldObjectByName("Technical Points")
pointSum += linkedIssue.getCustomFieldValue(technicalPointsField)?:0
}
}
return pointSum
}

Image of it working:

Screen Shot 2017-08-31 at 11.42.26 AM.png

Joshua Yamdogo _ Adaptavist
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.
Aug 31, 2017

You should also make sure that the Template for the Scripted Field is set to "Number Field" and that the Searcher is set to "Number Searcher". 

Screen Shot 2017-08-31 at 11.58.34 AM.png

Hi Joshua,

 

The query is giving me the error.

It says "The variable issue is not declared"

 

Please help

Screen Shot 09-04-17 at 02.04 PM.PNG

Thank you,

Swapnil Tiwari

Daniel Yelamos [Adaptavist]
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.
Sep 04, 2017

Hi Swapnill.

That is an inline error, not a compilation error. The script could be working at compilation time. Could you save the script regardless and try to see if the script works?

Cheers!

Dyelamos

Hi Daniel,

 

It is not working.

 

Thank you,

Swapnil Tiwari

Joshua Yamdogo _ Adaptavist
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.
Sep 04, 2017

Hi Swapnil,

You are using this code inside of a scripted field, correct? Which version of ScriptRunner are you using?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events