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?
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this one:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.link.IssueLinkManager IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager(); String[] allowedStatuses = {"closed"; "Completed"}; for(Issue curIssue: issueLinkManager.getOutwardLinks(issue.id)){ if(curIssue.getIssueTypeObject().getName() != "Epic"){ if( !allowedStatuses.contains(curIssue.getStatusObject().getName())) return false; } } return true;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As i mentioned that i tried with the below mentioned code and it worked but there seems to be an issue when there are no linked issue to the main ticket yet it is throwing exception.How can i get rid of that keeping the functionality of my code same basically it should by pass the validation when no linked issues are there.Code implemented is as below:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.