Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how to validate linked issuetype and link type?

jun lee
Contributor
February 13, 2023

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
}

1 answer

0 votes
Nic Brough -Adaptavist-
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.
February 14, 2023

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

  

Suggest an answer

Log in or Sign up to answer