I need a simple script to check if all linked issues which are "is blocked by" are resolved before r

tazeenn March 6, 2019

I need a simple script to check if all linked issues which are "is blocked by" are resolved before resolving the issue

 

2 answers

1 accepted

0 votes
Answer accepted
Ben Poulson
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.
March 6, 2019
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
def allClosed = true
List<IssueLink> allInIssueLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (link in allInIssueLinks)
{
if(link.issueLinkType.name == "Blocks")
{
def linked = link.getSourceObject()
if( linked.resolution == null) //You might need to modify this depending on how your project is set up
{
allClosed = false
}
}
}
return allClosed

 You might need to change how it determines if an issue is resolved depending on how your project is set up, but this should work.

tazeenn March 6, 2019

thanks Ben, shall I add this as validator under simple validator script  in workflow transition

Ben Poulson
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.
March 7, 2019

@tazeenn 

Did it work? If so, could you mark my response as the answer?

tazeenn March 7, 2019

Hey Ben, It is not working.

I added this as validator in the transition however the ransiiton is not stopped if  an open blocked by link is available. Its still letting the issue closed

with_Upgrade_implemented_JIRA.png

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
def allClosed = true
List<IssueLink> allInIssueLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (link in allInIssueLinks)
{
if(link.issueLinkType.name == "Blocks")
{
def linked = link.getSourceObject()
if( linked.resolution == Unresolved) //You might need to modify this depending on how your project is set up
{
allClosed = false
}
}
}
return allClosed


Ben Poulson
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.
March 7, 2019

Delete the validator, then recreate it. Instead of choosing "Simple Scripted Validator", choose "Custom Script Validator".

tazeenn March 7, 2019

ok. I will do that and let you know. I am marking it as answer for now

tazeenn March 7, 2019

Hi ben,

I added in custom validator but still the code is letting the issue closed even though there is a "blocked by" issue linked to it'

code.png

Ben Poulson
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.
March 15, 2019

Sorry, been a busy week, just saw this. I misunderstood your original problem- I thought you wanted to only allow the ticket to be closed if all the tickets blocking it were closed, not the other way around. To switch it, just change:

List<IssueLink> allInIssueLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());

to

List<IssueLink> allOutIssueLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

You'll also need to change all uses of allInIssueLinks to use allOutIssueLinks instead. Other than that, you should be good to go.

Maksym Mishchenko
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 20, 2024

If anyone finds this and it isn't quite working out for them. 
replace 

getSourceObject()

with 

getDestinationObject()

because SourceObject is the issue you're in and not the issue on the other side of the link which you want to use for your validator. 

0 votes
tazeenn March 18, 2019

no luck:( Its still letting the issue close even thought the linked issue is open

Suggest an answer

Log in or Sign up to answer