Forums

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

Add workflow condition - At least 1 issue must be linked

Celik Vedat July 16, 2018

Dear community,

 

I've tried to find a solution, but could only find something like "Linked status validation" or a solution with some plugins I don't use. We only use script runner. Someone has a idea for a groovy script to get a resolution here?

 

Befor a certain transition can be done, there must be at least one issue (relationship does not matter) linked to the issue. I'd like to get this into a code but always struggle with the script runner APIs and I am not really used to groovy..

The condition is "simply": Linked issues != null.

 

Thanks in advance

Vedat

1 answer

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 16, 2018

We used the following script to assure that there is at least one link of a particular type and that the linked issue is complete. 

Our script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def issueLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def numClosedPceIssues = 0

for(IssueLink i in issueLinks)
{
//want only PCE links
if(i.getIssueLinkType().getName() == "PCE")
{
def linkedObject = i.getDestinationObject()
//want only PCE issues with resolution of Complete
if(linkedObject.getIssueType().getName() == "PCE" && linkedObject.getResolution()?.getName() == "Complete")
{
numClosedPceIssues++
}
}
}

return numClosedPceIssues > 0

 Sounds more complex than you need, so you can likely pare it down to:

import com.atlassian.jira.component.ComponentAccessor
def issueLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
return issueLinks.size() > 0

You may also wish to check inward and outward links if direction doesn't matter, e.g.

import com.atlassian.jira.component.ComponentAccessor
def outwardLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def inwardLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId())
return outwardLinks.size() + inwardLinks.size() > 0

Suggest an answer

Log in or Sign up to answer