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 ?
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.ComponentAccessordef issueLinkManager = ComponentAccessor.issueLinkManagerdef loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef customFieldManager = ComponentAccessor.customFieldManagerdef storyPoints = customFieldManager.getCustomFieldObjectsByName('Story Points').first()issue.getCustomFieldValue(storyPoints) as Doubledef 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:-
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:-
2) The test is done using the MOCK-4 issue. An issue link to MOCK-1 is created, as shown in the screenshot below:-
3) Once the issue has been linked, it will display the Story points from the completed issue MOCK-1
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:-
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:-
6) Finally, the issue MOCK-2, which has already been completed, will be linked as shown below:-
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.
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 ?
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,
Has your question been answered?
If yes, please accept the solution.
Thank you and Kind regards,Ram
It looks like you're new here. Sign in or register to get started.