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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script to calculate sum between parent issue and subtasks

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

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

Thanks a lot Joshua,

I will test it :)

sorry commented with another id

 

Thanks a lot Joshua,

I will test it :)

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.

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.

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 ?

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 ?

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you