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,463,539
Community Members
 
Community Events
176
Community Groups

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

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.

 

2 answers

1 accepted

1 vote
Answer accepted

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

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

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

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 

Suggest an answer

Log in or Sign up to answer