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)
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
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)
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.