Validator to check at least 1 linked issue exists in a known project

graemejohnson October 4, 2017

Ahead of a specific workflow transition I need to validate that at least 1 linked issue is attributed to the current issue, and that linked issue is in a given project.

I know nothing about groovy scripting - but by the power of Google and some guess work came up with the example below....

However, even though I have a linked issue attributed to the issue I am transitioning, the for loop is not entered.

Please can anyone advise?

Happy to accept a neater solution as well (perhaps one that allows me to work from the name/key of the project rather than the internal project id)

sample_script.png

2 answers

2 votes
Joshua Yamdogo @ 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.
October 9, 2017

Hello Graeme,

I think that your script is very close to being correct, but I believe it could be simplified.

I would add a Simple Scripted Validator to your workflow transition. In the validator, you could have a script that looks at issues that the current issue links FROM. If one of those issues is in a specific project, return true and allow the transition.

def foundLink = false
(issueLinkManager.getInwardLinks(issue.id) ).each {issueLink -> // go through all issues linked FROM this issue
def linkedIssue = issueLink.getSourceObject()
log.debug(linkedIssue.getProjectObject().getKey())
if (linkedIssue.getProjectObject().getKey() == "JRTWO") { // your project key here
foundLink = true
}
}
foundLink

Note: this script only checks to see that the user has linked an issue TO the current issue. If you want to allow the transition if the user has linked an issue FROM the current issue, you'd need to check outward links as well.

def foundLink = false
(issueLinkManager.getOutwardLinks(issue.id) ).each {issueLink -> // go through all issues linked FROM this issue
def linkedIssue = issueLink.getDestinationObject()
log.debug(linkedIssue.getProjectObject().getKey())
if (linkedIssue.getProjectObject().getKey() == "JRTWO") { // your project key here
foundLink = true
}
}
(issueLinkManager.getInwardLinks(issue.id) ).each {issueLink -> // go through all issues linked TO this issue
def linkedIssue = issueLink.getSourceObject()
log.debug(linkedIssue.getProjectObject().getKey())
if (linkedIssue.getProjectObject().getKey() == "JRTWO") { // your project here
foundLink = true
}
}
foundLink
0 votes
Azfar Masut
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.
May 12, 2022

simplest for generic just checking if link exist + additional use case is as such, added a bit more from Joshua:

def flag = false

//if (issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('<issuelinktypename>') || issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('<issuelinktypename>'))

if (issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name != null)
{
flag = true
log.warn(issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name)
log.warn('success')
log.warn(flag)

}

log.warn('final flag: '+flag)
return flag

 replace '<issuelinktypename>' accordingly with link type name (the link category)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events