Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,328
Community Members
 
Community Events
165
Community Groups

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

2 answers

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)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

390 views 0 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you