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

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.

 

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.
Dec 03, 2022 • edited

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.
Dec 09, 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

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

@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?

@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.
Aug 09, 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.
Aug 09, 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

@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 

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 

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