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,464,971
Community Members
 
Community Events
176
Community Groups

Workflow validator - check linked issues

Edited

Hi community!

I'm trying to write a validator script that checks if an Epic got linked issues.

if yes -  the workflow transition can move, otherwise it sends an error message.
so far I got this but it's not working for me. (Using Jira server).

Code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.opensymphony.workflow.InvalidInputException

// Allow logging for debug and tracking purposes
import org.apache.log4j.Level
import org.apache.log4j.Logger


// Setup the log and leave a message to show what we're doing
Logger logger = log
logger.setLevel( Level.ERROR )
logger.debug( "$scriptCode Triggered by $issue.key" )

def passesCondition = true
if (issue.linkedIssues.size() > 0)
{
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
def found = issueLinkManager.getOutwardLinks(issue.id).any{ }

logger.debug( "$scriptCode Found = $found " )
if (found) {
logger.debug( "$scriptCode return false" )
passesCondition = false
invalidInputException = new InvalidInputException("Please create issues")
} else {
logger.debug( "$scriptCode return true" )
passesCondition = true
}
}
else
{
passesCondition = true
}

1 answer

1 accepted

1 vote
Answer accepted

Are you looking for your Epic to have regular issue links?

Or are you looking for "epic link" or "issues in epic" link?

Because those are different.

The IssueLinkManager will only get you issue links like "Cloned By", "Related To", "Blocks" etc.

If you want to look to see if the epic has issues in the epic link, then you need to EpicLInkManager

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
@WithPlugin("com.pyxis.greenhopper.jira") agilePlugin
@JiraAgileBean EpicLinkManager epicLinkManager

def issuesInEpic = epicLinkManager.getIssuesInEpic(issue)
if(issuesInEpic) {
log.debug "${issuesInEpic.size()} issues were linked to this epic."
return true
} else {
log.debug "No issues are linked to this epic"
return false
}

Hi @Peter-Dave Sheehan thanks for your response.

I used:

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.opensymphony.workflow.InvalidInputException
@WithPlugin("com.pyxis.greenhopper.jira") agilePlugin
@JiraAgileBean EpicLinkManager epicLinkManager

import org.apache.log4j.Logger
import org.apache.log4j.Level
 
def log = Logger.getLogger("com.acme.ListLinks")
log.setLevel(Level.DEBUG)


def passesCondition = true
def issuesInEpic = epicLinkManager.getIssuesInEpic(issue)

if(issuesInEpic) {
    log.debug "${issuesInEpic.size()} issues were linked to this epic."
    passesCondition = true
} else {
    log.debug "No issues are linked to this epic"
    invalidInputException = new InvalidInputException("Please create linked issues to this Epic in order to transition the Epic to 'DEV TO DO' status")
    passesCondition = false
}



Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events