Prevent Workflow Transition to Done if Linked Issues "is blocked by" are not Done using scriptrunner

Christina Hiller June 24, 2019

Problem:

Prevent the workflow transition "Done" from showing up if there are any "is blocked by" linked issues that are not "Done"

Scenarios:

In this scenario, I DO NOT want to see an option to move the Story A status to "done"

  • Story A  (current status=in progress)
  • is blocked by Story B (current status = done)
  • is blocked by Story C (current status = to do)
  • relates to Story D (current status = to do)

In this scenario, I DO want to see an option to move the Story A status to "done"

  • Story A  (current status=in progress)
  • is blocked by Story B (current status = done)
  • is blocked by Story C (current status = done)
  • relates to Story D (current status = to do)

Attempted Solution:

In the workflow, I've added a scripted condition, however the "Done" status is still an option for the user and I'm able to complete the "Done" transition. linkedIssues_1.png

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

def linkType = ["is blocked by"]

def linkMgr = ComponentAccessor.getIssueLinkManager()
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.name)) {
if (! link.sourceObject.resolutionId) {
passesCondition = false
}
}

}

I used this link as my reference. https://scriptrunner.adaptavist.com/5.0.2/jira/recipes/workflow/conditions/all-dependent-issues-resolved.html 

Any advice ??

2 answers

1 accepted

2 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2019

I think your error is here:

link.issueLinkType.name

this will return "Blockers" or whatever name you have for the link type. Not the directional name.

For that, you want  

link.issueLinkType.inward

 So try

if (linkType.contains(link.issueLinkType.inward)) {...}

This should result in the Done button being hidden. 

Christina Hiller June 24, 2019

Thanks for the help!  Your suggestion worked like a charm!

 

The final...

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

def linkType = ["is blocked by"]

def linkMgr = ComponentAccessor.getIssueLinkManager()
for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.inward)) {
if (! link.sourceObject.resolutionId) {
passesCondition = false
}
}

}
Like # people like this
2 votes
Srikanth Mamidala May 6, 2020

Came across the same issue, can this be done via new Automation? If yes how? 

Ivan Ferreira
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 17, 2022

Yes. It can be done with automation, but there is something that you need to consider. For this rule to work with automation, must be a multi-project rule. Multi-project rules have execution limits according to your suscription plan. If you are on a standard plan, you only have 1.000 executions, and this rule will be executed every time a issue is resolved.

The rule would be something like this:

 

  • Condition on linked issues
  • Link type: is blocked by (and others you use)
  • Condition: Some match the specified JQL
  • JQL condition: status not in ("RESOLVED", "CLOSED", "CANCELLED")
  • Rule restricted to project: "Project A, Project B... (or all projects)"

 

Clic here for more information.

Like Kalos Bonasia likes this
Paul Heath Armengol April 24, 2024

How does your automation "Prevent Workflow Transition to Done" if it's executed after the issue has already been resolved?

 

Suggest an answer

Log in or Sign up to answer