I want to set validation condition like
: if liked issue type id is 10609, and link type id is 11100 → true
: if liked issue type id is not 10609, and link type id is 11100 → false
: if liked issue type id is 10609, and link type id is not 11100 → true
: if liked issue type id is not 10609, and link type id is not 11100 → true
In sum, several types of issues may be connected with several connection types. if there is a issue type 10609, validation rule has to check whether the link type is 11100 or not.
If even one condition is false, the result value must be false.
For example, when issue type = 10609 & link type = 11100, issue type = 10610 & link type = 11100, issue type = 10609 & link type = 11111, and issue type = 10610 & link type = 11111, validation should be false.
when issue type = 10609 & link type = 11100 and issue type = 10609 & link type = 11111, validation should be true.
I tried like below, but it doesn't work properly.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import utils.*
def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())
def linkId = "11100" //TEST link
if(links != null) {
for(link in links) {
if(link.getLinkTypeId() == Integer.parseInt(linkId)) { // TEST link
def linkedIssue = link.getDestinationObject()
if(linkedIssue.issueTypeId == "10609"){ // Release issuetype
return true
}
}
else {
if(link.getLinkTypeId() == Integer.parseInt(linkId)) { // TEST link
def linkedIssue = link.getDestinationObject()
if(linkedIssue.issueTypeId != "10609"){ // Release issuetype
return false
}
} else {
if(link.getLinkTypeId() != Integer.parseInt(linkId)) { // TEST link
def linkedIssue = link.getDestinationObject()
if(linkedIssue.issueTypeId == "10609"){ // Release issuetype
return true
}
} else {
if(link.getLinkTypeId() != Integer.parseInt(linkId)) { // TEST link
def linkedIssue = link.getDestinationObject()
if(linkedIssue.issueTypeId != "10609"){ // Release issuetype
return true
}
}
}
}
}
}
} else {
return true
}
There's a big structural problem in here, and also, you're overthinking and hence over-coding it.
You have not told us what the code is trying to achieve, but I think the intention is "fail validation if there are any links of type 11100 that are linked to an issue type that is not 10609"
The problem with your code is you are trying to code for every situation, and as soon as you find a match for any of your rules, the script finishes.
So you should simplify it. Only look for the case where you need it to fail. (You're also doing unnecessary work in the script, so I've removed that too)
def linkId = 10609
if(links != null) {
for(link in links) {
if(link.getLinkTypeId() == linkId) {
if (link.getDestinationObject().issueTypeId != "10609"){
return false
}
return true
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.