Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,555,977
Community Members
 
Community Events
184
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

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.
Oct 09, 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