Calculate sum of Story Points in all linked issues, except the issueLinkType "is blocked by"

Shahin Dogan December 1, 2022

Hello Community,

I´ve found an script to calculate the sum of Story Points in all linked Issues with a scripted field via ScriptRunner and adjusted it to my use case like this: 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

// The issue type for which we want the scripted field to be displayed
final issueTypeName = 'Story'

// The values of that custom field - of type number - we want to sum up
final numberOfUsersFieldName = 'Story Points'

if (issue.issueType.name != issueTypeName) {
    return null
}

def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll { it.destinationObject.issueType.name }
if (!linkedIssues) {
    return null
}

def numberOfUsersField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().destinationObject).findByName(numberOfUsersFieldName)
if (!numberOfUsersField) {
    log.debug "Custom field is not configured for that context"
    return null
}

linkedIssues*.destinationObject.sum { Issue it -> it.getCustomFieldValue(numberOfUsersField) ?: 0 }

Now the requirement has changed, and I would like to have the sum of Story Points in all linked issues except the issueLinkType "is blocked by". In case that I´m not a developer and new to jira, I have no clue how to modify this script, to run it for my use case. I hope that someone has an idea. Thank you in advance for your support.

 

3 answers

1 accepted

1 vote
Answer accepted
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.
December 3, 2022

Hi @Shahin Dogan

For your requirement, you should try something like this:-

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) // to get all the linked issues for the current issue
def excludedIssues = linkCollection.getInwardIssues('Blocks')
def totalStoryPoints = linkCollection.allIssues - excludedIssues // to filter out issues that are blocked

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

Please note that the sample working 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's configuration:-

scripted_field_config.png 

I also include a couple of test screenshots for your reference:-

The first issue is linked to 3 other issues. Two are using the relates to link, and one is using the is blocked by link. If you compare the first screenshot below with the other three screenshots, you will notice that in the issue MOCK-1, only the story points from MOCK-2 and MOCK-3 are calculated. However, the story points from MOCK-4 are excluded because it is a blocker.

test1.png

test2.png

test3.png

test4.png

I hope this helps to solve 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.
December 9, 2022

Hi @Shahin Dogan

Does the solution I provided answer your question?

If yes, could you please accept the solution?

Thank you and Kind regards,

Ram

Shahin Dogan December 9, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_

first of all thank you very much for the detailed answer. I have to apologize, that I didn´t answered yet. I was very busy this week due to other subjects in my company. In case of that I couldn´t test ist yet. I will response and accept your solution until Monady evening.

I hope that this is okay for you.

Thank you and  kind regards.

Shahin

jun lee
Contributor
February 19, 2023

@Ram Kumar Aravindakshan _Adaptavist_ 

Hi

 

I also want to calculate custom field like

condition 1 : linked id = 10309, 10703

condition 2 : issue type id = 10511, 10612, 10603

condition 3 : linked issue status = completion

calcuate and update custom field ("ENM_Planpercent") : (number of condition1 & condition2 & condition3) / (total number of condition1) x 100

 

Can you help me?

jun lee
Contributor
February 23, 2023
vashim.shekh August 4, 2023

@Ram  hi,

 

I have one issuetype as feature and i need to created on scripted filed for check and how many linked feature card count on epic level can you solve this.

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.
August 9, 2023

Hi @jun lee

In your previous comment, you mentioned:-

I also want to calculate custom field like

condition 1 : linked id = 10309, 10703

condition 2 : issue type id = 10511, 10612, 10603

condition 3 : linked issue status = completion

calcuate and update custom field ("ENM_Planpercent") : (number of condition1 & condition2 & condition3) / (total number of condition1) x 100

Could you please specify what link types 10309 and 10703 refer to?

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.
August 9, 2023

Hi @vashim.shekh 

In your previous comment, you mentioned:-

I have one issuetype as feature and i need to created on scripted filed for check and how many linked feature card count on epic level can you solve this.

If you expect to get the could from the Initiative to the Epic via child link. This is not directly doable.

You would first have to create a custom link, for example, Parent / Child, and link your Feature with the Epic issue accordingly. Only once this is done will you be able to get a count for the Features and Epics.

Thank you and Kind regards,

Ram

0 votes
vashim.shekh August 8, 2023

@Ram Kumar Aravindakshan _Adaptavist_  Hi Can you help on need to make one scrip field to calculate total count of Feature an epic link .

*note - not require for issue link count 

0 votes
Shahin Dogan December 12, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_

thank you again for the effort. After some tries, I´ve figured out the right modification for our instance. Now it´s working pretty well.

best regards

Shahin 

Pratibha Tambakad April 27, 2023

Hey RamKumar,

My requirement is bit similar to this but tried myself couldn't achieve it. I want to get the sum of Story points under epic.

Currently Stories are linked to epic using epic link. I have to calculate all the stories story points that are linked epic using epiclink and sum their story points and display.

Will that be possible?

Suggest an answer

Log in or Sign up to answer