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,552,516
Community Members
 
Community Events
184
Community Groups

Scripted validator that validates that there is at least one issue linked to Epic

I'm trying to setup a 'Simple scripted validator'; when the value of a field called 'Requirements needed' (dropdown field) is set to 'Yes', there must be at least one issue linked to the Epic under 'Issues in epic'. The issue linked should be issue type 'Requirement'. If the requirements of this validation are met, the transition should proceed.

When the 'Requirements needed' field value is set to 'Yes', but there is no 'Requirement' issue linked, the transition should fail.

When the 'Requirements needed' field value is set to 'No', the transition should proceed.

I'm not very good at scripting, so I tried to put something together by using already existing scripts in our environment and Googling, but I can't get the validator to work properly.

The script I have now is:

if(cfValues['Requirements Needed']?.value == 'Yes'){
    ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id)?.find {it.issueLinkType.name == "Epic-Story Link"}
}else {
    return true
}

This results in the issue transitioning when 'Requirements needed' is set to 'No', which is good. But in any case, with or without an issue link, the transition fails when 'Requirements needed' is set to 'Yes', which is not good.

I know the script is missing some requirements I mentioned above, but I just can't figure out how to add these requirements to the script.

I hope someone can help me with this!

1 answer

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 09, 2022

You can access epic linkages from the IssueLinkManager. For that, you need the EpicLinkManager

Try this:

import com.atlassian.jira.component.ComponentAccessor
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

if(cfValues['Requirements Needed']?.value == 'No') return true

epicLinkManager.getIssuesInEpic(issue).any{it.issueType.name == 'Requirement'}

Quit early with return true is Requirements Needed is No (allows a flatter view of the script, no unnecessary indents).

Then use the epicLink manager to retrieve the issues in the epic and return either true or false if at least one of them is a Requiement.

The "@WithPlugin" line allows you to import from com.atlassian.greenhopper package.

The @JiraAgileBean is a convenience annotation provided by scriptrunner to instantiate managers and services from that package.

Hi Peter-Dave,

Thank for the help and explanations. I tried it, and it works perfectly!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events