I have a Workflow validation script as below:
def found = ((issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.issueTypeObject.name != "Epic"}) && (issueLinkManager.getOutwardLinks(issue.id).any {it.destinationObject.statusObject.name != 'Closed'}))return !found
What it does is to prevent issue transition to a specific Status when the linked issues other than Linked Epic has Status not Closed.
I want to include a Status called Completed in it i.e The issue can transition if the Linked issue is either in Closed or Completed Status.The other part of the validator remains the same.
How can I achieve that?
Try this code:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.IssueLinkManager IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager(); def found = ((issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.issueTypeObject.name != "Epic"}) && ( (issueLinkManager.getOutwardLinks(issue.id).any {it.destinationObject.statusObject.name == 'Closed'}) || (issueLinkManager.getOutwardLinks(issue.id).any {it.destinationObject.statusObject.name == 'Completed'} ) ) ) return !found
This does not work.It works for first level i.e. Closed but for the second it is not validating as expected.In my linked issue there is a ticket of Status Completed which ideally should let the main ticket to go to next status but its not.
I have something similar; my script looks for outward links of type "dependency", and prevents the transition if there isn't one that is unresolved. Your case sounds similar; I had to make certain I was looking at the status of the specific link(s) of interest, while you are checking against type and status separately, which I think could be an issue. For example, if you have two outward links where one is an Open Epic, and the other is a Closed Whatever, your "found" condition will still be met. I think you want:
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.link.IssueLinkManager; IssueLinkManager issueLinkManager = ComponentManager.getInstance().getIssueLinkManager(); Boolean found = false; for (IssueLink link in issueLinkManager.getOutwardLinks(issue.id)) { if (link.getIssueLinkType().getName()!="Epic") { if(link.getDestinationObject().getStatusObject().getName() != "Closed" && link.getDestinationObject().getStatusObject().getName() != "Completed") { found = true; } } } return !found;
The above code will require that all non-Epic outward links (if any) be completed/closed. If you want just one, then use:
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.link.IssueLinkManager; IssueLinkManager issueLinkManager = ComponentManager.getInstance().getIssueLinkManager(); Boolean found = false; for (IssueLink link in issueLinkManager.getOutwardLinks(issue.id)) { if (link.getIssueLinkType().getName()!="Epic") { if(link.getDestinationObject().getStatusObject().getName() == "Closed" || link.getDestinationObject().getStatusObject().getName() == "Completed") { found = true; } } } return found;
This version will also require that there be at least one non-Epic link.
Lets try to understand each other.
We have some issue and several linked issues. If one of NOT Epic issues is into Closed or Completed status this transition should be done.
Is it correct?
Consider my main issue is Release and the Release has many Defects Stories and Release Linked to it.The requirement is until all the linked issue(apart from Epic,Epic can be at any Status) are in either Completed or Closed the main Release ticket Cannot be marked to some specific Status say Closed.
Hope that Clarifies.
I tried with the below code and it worked
def found = false; if ((issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.issueTypeObject.name != "Epic"}) && (issueLinkManager.getOutwardLinks(issue.id).any {it.destinationObject.statusObject.name == 'Closed'}) ) found = true; else if((issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.issueTypeObject.name != "Epic"}) && (issueLinkManager.getOutwardLinks(issue.id).any {it.destinationObject.statusObject.name == 'COMPLETED'})) found = true; return found
It looks like you're new here. Sign in or register to get started.