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!