Script to calculate sum between parent issue and subtasks

Deleted user February 22, 2018

Hello Team,

I am having a requirement like,
I want to calculate the value between the Parent Issue and subtask,

Example :
If there is Issue STORY. 
In that we are having a field like STORYPOINTS
In STORYPOINTS i have given a value example-3
and the subtask I have give some value for STORYPOINT Example-2
And the same thing in the other subtask of the same parent issue.
Now I want to calculate the values of different Story points and I want to display them in the parent issue(STORY).
Please suggest the right way to proceed further to resolve this topic.

Thank you.
Regards.
Varun Joseph Allu.

4 answers

2 votes
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.
February 22, 2018

Hi Varun,

I created this script for a script field of type Number:

import com.atlassian.jira.component.ComponentAccessor

if (issue.getIssueType().name == "Story") {
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def storyPointsField = customFieldManager.getCustomFieldObjectByName("Story Points")
def pointSum = 0
pointSum += issue.getCustomFieldValue(storyPointsField)?:0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
def linkedIssue = issueLink.getDestinationObject()
if (linkedIssue.getIssueType().name == "Sub-task") {
pointSum += linkedIssue.getCustomFieldValue(storyPointsField)?:0
}
}
return pointSum
}
  • First checks to see if the issue type is "Story"
  • It gets the value of the "Story Points" field on the Story issue, adds value to pointSum
  • Next it searches all sub-task issues linked from the parent "Story" issue. For each sub-task, it will add the value of their "Story Points" field to pointSum
  • pointSum is returned
  • Script field shows total story point sum on the parent "Story" issue only

Let me know if it works.

Joshua

Deleted user February 22, 2018

Thanks a lot Joshua,

I will test it :)

Deleted user February 22, 2018

sorry commented with another id

 

Thanks a lot Joshua,

I will test it :)

0 votes
Deleted user January 14, 2021

You can now do this using Jira's built-in automation: https://www.atlassian.com/fr/software/jira/automation-template-library/sum-up-story-points 🎉

0 votes
Deleted user March 6, 2018

Hello Joshua,

 

Thanks a lot for your help,

 

I have implemented the scripting field.

I found one error with that,

If we have given Story Points 2 in the parent issue,

And in subtask story points 3

The total 5 should be displayed in the parent issue..

But the story point(2) I have given in the parent issue is copied to the subtask and it is displaying total story points as 4 instead of 5,

When we manually edit the subtask story point it is showing the accurate calculation ...

Please help me in this error.

 

Thanks a lot in advance.

 

Regards,

Varun.

Varun.

0 votes
Deleted user March 5, 2018

Hello Mr.Joshua.

 

Thanks for the script it is working fine.

I am having a question,

What are the changes that I have to do in the script to make that available for all issue types,

Now the script is only for Story issue type, I want to modify it for all other issue types in the project.

So that, it will calculate all subtasks story points in the Jira project.

 

Thank & regards,

Varun.

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.
March 6, 2018

Hi Varun,

If you remove the first 'if' statement that checks to see if the issue type is a story, this script should work for all the other issue types. Like this:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def storyPointsField = customFieldManager.getCustomFieldObjectByName("Story Points")
def pointSum = 0
pointSum += issue.getCustomFieldValue(storyPointsField)?:0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
def linkedIssue = issueLink.getDestinationObject()
if (linkedIssue.getIssueType().name == "Sub-task") {
pointSum += linkedIssue.getCustomFieldValue(storyPointsField)?:0
}
}
return pointSum

Now every issue in your project will display this script field.

Sara March 6, 2018

Hi @Mr. Joshua Ray Yamdog ,

  should we place this scripted field on project screens if we want to see it on particular projects or it will display globally ?

Sara March 6, 2018

And last time when I created a scripted field for sprint start date and end date, the reindex took very long time and Atlassian said that because of the scripted field it is taking time and failing Any thoughts ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events