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

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

1 answer

0 votes

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,396 views 0 8
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you