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,555,285
Community Members
 
Community Events
184
Community Groups

Script to calculate sum of completed story points.

Hi,

Can someone help me with the script which can calculate completed story points. Which means sum of story points of linked stories which are in closed status linked within an epic issue type. There is an example available to calculate total story points already. But how to calculate completed story points ?

 

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
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 08, 2023 • edited

Hi @Alok Kumar

For your requirement, I would recommend using the Scripted Field.

Below is a sample working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager

def storyPoints = customFieldManager.getCustomFieldObjectsByName('Story Points').first()
issue.getCustomFieldValue(storyPoints) as Double

def linkCollection = issueLinkManager.getLinkCollection(issue, loggedInUser)
def totalStoryPoints = linkCollection.allIssues.findAll {it.status.name == 'Done'}

totalStoryPoints.collect {
it.getCustomFieldValue(storyPoints) as Double
}.sum()

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Scripted Field configuration:-

scripted_field_configuration.png

Below are a couple of test screenshots for your reference:-

1) Firstly, the two issues that will be tested are MOCK-1 and MOCK-2. Both of these issues are in the Done status  as shown in the screenshots below:-

mock1.pngmock2.png

2) The test is done using the MOCK-4 issue. An issue link to MOCK-1 is created, as shown in the screenshot below:-

test1.png

3) Once the issue has been linked, it will display the Story points from the completed issue MOCK-1

test2.png

4) The next test is to link an issue that has not been closed. MOCK-3 that is still in the To-Do status will be linked as shown below:-

test3.png

5) Once the MOCK-3 issue is linked, there will be no difference in the total points calculated in the Scripted Field as shown in the screenshot below:-

test4.png

 

6) Finally, the issue MOCK-2, which has already been completed, will be linked as shown below:-test5.png

7) Once it has been linked, as expected, the scripted field will be updated with the total of story points from the closed issues, i.e. MOCK-1 and MOCK-2.test6.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram 

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thanks for your response. 

I forgot to mention and tag that i was looking this for Jira Cloud.

I have this script running in Jira server already. Will you be able to help me to generate script for scriptrunner cloud ?

Ram Kumar Aravindakshan _Adaptavist_
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 09, 2023 • edited

Hi @Alok Kumar

If you intend to do this for the cloud, you can use the sample working code below:-

def issueKey = issue.key

/*To store the story points from the issues that are in Done status*/
def storyPoints = [] as List<Double>

def result = get("/rest/api/2/issue/${issueKey}").header('Content-Type', 'application/json').asObject(Map)

if (result.status == 200){

/*To extract the status name of the linked issues*/
def statusName = result.body.fields.issuelinks['inwardIssue']['fields']['status']['statusCategory']['name'] as List<String>

/*To extract the list of linked issues linked to the current issue that is being viewed*/
def linkedIssueKey = result.body.fields.issuelinks['inwardIssue']['key']

/*To verify that the status of the linked issue(s) is Done*/
if (statusName.first().toString() == 'Done') {

linkedIssueKey.each {
def linkedIssues = get("/rest/api/2/issue/${it}").header('Content-Type', 'application/json').asObject(Map)

if (linkedIssues.status == 200) {
/*To extract the story points from the linked issues and store in the story points list

Please ensure that the default value for the Story Points is set to 0. This is to avoid
any error if the Story Points is not added to any of the linked issues.
*/
storyPoints << Double.parseDouble(linkedIssues.body.fields.customfield_10030.toString())

} else {
"Failed to find issue: Status: ${result.status} ${result.body}"
}
}
}

/*To calculate and return the total story points of all the linked issues that are done*/
storyPoints.sum()

} else {
"Failed to find issue: Status: ${result.status} ${result.body}"
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

In the sample code above, you will notice a custom field invoked, i.e. customfield_10030. This refers to the Story Points field. You must double-check this custom field id as it may differ in your environment.

Also, please ensure that all the Linked Issues that are already in Done status have a value in the Story Points field. If you do not intend to add any Story Points for a particular issue, ensure that you set the Story Points field to 0, else there will be an error in the calculation.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
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 11, 2023

Hi @Alok Kumar

Has your question been answered?

If yes, please accept the solution.

Thank you and Kind regards,
Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Sorry for the delayed reply. 

I tried the same script, but it is giving type error.

script_error.png

Ram Kumar Aravindakshan _Adaptavist_
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 15, 2023 • edited

Hi @Alok Kumar

Could you please share a full screenshot of your Scripted Field configuration?

Also, please share a screenshot of the issue and linked issues that you are testing with.

I've run the test in the cloud instance and don't seem to be encountering this error.

Have you read through my last comment and ensured that you had added value to all the Story Points fields?

If no Story Point is to be added to a particular issue, you need to set the value to 0 and not blank.

Below is a full screenshot of the Scripted Field configuration for your reference:-

image.png

If you observe the screenshot above, I'm not encountering any issue.

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Scripted field configuration:

1.png2.png3.png4.png

all linked storied have story points value. I have changed the value of custom field value in the script.

Ram Kumar Aravindakshan _Adaptavist_
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 15, 2023 • edited

Hi @Alok Kumar

Can you please remove the Epic issue type from the Issue Type/s field and retest it once again?

Also ensure that the current issue you are testing with does not have any Epics linked to it.

That seems to be the cause of your issue.

Thank you and Kind regards,

Ram

Even if i remove epic issue type from issue type section, It still gives same error.

Ram Kumar Aravindakshan _Adaptavist_
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 26, 2023

Hi @Alok Kumar

Please confirm if you have ensured that the issues you are testing with have no Epics linked to them, i.e. Epics added to the linked issues when re-running the test.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events