Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted Field - How do I returned linked Issue count based on conditions of linked issues

Andrew Zimmerman
Community Champion
April 29, 2019

Hi there,

Using Scriptrunner for Jira Server, I'm trying to return a number count of linked issues if those linked issues meet certain conditional requirements.

Namely, I'm looking to input a count into a scripted field (one with a Number Field template called "Upsell Count"). This script should only run on "Invoice" issuetypes.

The count should = the number of "Upsell" issues linked to the "Invoice" if the resolutions of the "Upsell" are NOT in ("Declined", "Deprecated").

I'm stuck on the resolution conditioning. Here's what I have so far. Anyone have ideas on how to accomplish what I'm looking for and/or improve what I already have?

import com.atlassian.jira.component.ComponentAccessor

if(issue.issueType.name == "Invoice")
{
int x = 0
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getAllIssues()
if (linkedIssues.size() > 0){
for (int i = 0; i < linkedIssues.size(); i++){
if (linkedIssues[i].getIssueType().getName() == "Upsell"){
x = x + 1
}
}
}


if (x > 0){
return x
}else return null
}

Thanks so much! My org is on Jira Server v7.12.3.

Cheers!

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Yen-Wu Lo
September 24, 2020

With the exact same code, I was able to solve this issue by upgrading to ScriptRunner 6.10.0.

I believe this is related to https://productsupport.adaptavist.com/browse/SRJIRA-4611.

TAGS
AUG Leaders

Atlassian Community Events