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!
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.