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,556,304
Community Members
 
Community Events
184
Community Groups

How to filter out linked issues based on issye type in the Scripted field

 

Hello!

I created a scripted field "Done Story Points" that should display the sum of values of another field from the linked issues.

It is works in two scenarios:

  • for Epics: displays a sum of Story Points from the issues it the Epic, include only those issues that are currently in the "Done" status
  • for Features: displays a sum of "Done Story Points" from Epics.

It works OK for the first scenario. But it is don't work as expected for the second. I'm trying to restrict the sum operation only to linked Epics (because Feature can be linked to another Feature with link type "Relates to"), but seems like the operator <if (issueType == "Epic")> does not work, like if the script is unable to get "IssueType" value from current linked issue. And as a result field shows sum of "Done Story Points" both from the Epics and from the related Features.
Please help to understand what I'm doing wrong and how can I get the sum of "Done Story Points" in the Feature ONLY from related Epics, ignoring other related Features?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;

def componentManager = ComponentManager.getInstance()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def spField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10002");
def DoneSpField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14715");
int totalSP = 0

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->;
def linkedIssue = issueLink.destinationObject
String issueType = issueLink.destinationObject.getIssueType().toString()
if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
def Basestatus = linkedIssue.getStatus().getName();
if (Basestatus=="Done"){
int spValue = (int) (issueLink.destinationObject.getCustomFieldValue(spField) ?: 0)
totalSP = spValue + totalSP;}
}

if (issueLink.issueLinkType.name == "Relates") {
if (issueType == "Epic"){
int spValue = (int) (issueLink.destinationObject.getCustomFieldValue(DoneSpField) ?: 0)

totalSP = spValue + totalSP;
}
}
}

return totalSP

 

1 answer

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 03, 2018

Hello @Elena Oleksenko

Is your Feature linked to an Epic via normal issue linking or via Epic link, because in that case an feature can be linked to not more than one epic.

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 03, 2018

Could you also may be try to execute the code with proper logging in the script console and use "IssueManager" to fetch the issueKey of an feature and see the output based on the above code if you get desired output or not.

Hi @Tarun Sapra!

Feature is linked to an Epic via normal issue linking, with "Relates to" link type. 

The problem is that Feature can be linked to another Feature with "Relates to" link type. And in this case the script will count "Done Story Points" both from Epics and from the second Feature. But I need values only from Epics. 

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 03, 2018

Could you try this code in script console and see if it returns expected result for the feature issue

You can use the following code to to get issue object

def issue = ComponentAccessor.issueManager.getIssueObject("<issue-key">)

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->;
def linkedIssue = issueLink.destinationObject
String issueType = issueLink.destinationObject.getIssueType().toString()

if (issueLink.issueLinkType.name == "Relates") {
if (issueType == "Epic"){
int spValue = (int) (issueLink.destinationObject.getCustomFieldValue(DoneSpField) ?: 0)

totalSP = spValue + totalSP;
}
}
}

return totalSP

 

And for getting issueType use

getIssueType().getName() instead of toString()

 

Using the above approach you can isolate the problem and just test the code for an actual feature in the script console and see if it returns story points sum only from the linked epics and not from linked features. The hardcoded issue-key should be from an feature.

Thank you @Tarun Sapra! Will try this

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 05, 2018

Hello @Elena Oleksenko

Did you try it, what was the outcome?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events