Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Stijn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 9, 2022

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

Suggest an answer

Log in or Sign up to answer
1 vote
PD Sheehan
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.
November 9, 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.

Stijn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 15, 2022

Hi Peter-Dave,

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

TAGS
AUG Leaders

Atlassian Community Events