I have two custom fields on my stories that I need to add some validation on. If the first custom fields value is "Yes" then the second custom field value must also be set to "Accepted" in order for a JIRA transition to be able to take place.
I have tried the two following approaches, both without much luck:
Approach 1:
import com.atlassian.jira.component.ComponentAccessor;
def pciChange = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("PCI Affecting Change?");
def cabApproval = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("CAB Approval");
def pciValue = (String)issue.getCustomFieldValue(pciChange);
def cabValue = (String)issue.getCustomFieldValue(cabApproval);
if (pciValue == 'Yes') {
if (cabValue != 'Accepted') {
return false
}
}
I have tried adding in error logging in this to try and find out the value of my variables during the process but nothing is being logged which would lead me to believe that my custom fields are not being found.
This approach resulted in the validation rule always being applied no matter what the value of "pciValue".
Approach 2:
cfValues["PCI Affecting Change?"]?.value != "Yes" || cfValues["CAB Approval"] != "Accepted"
This approach resulted in seemingly no validation being applied at all.
Any advice or links to documentation that would help solve this would be much appreciated!
Hello @David Nattrass
Try this
!(cfValues["PCI Affecting Change?"]?.value == "Yes" && cfValues["CAB Approval"] != "Accepted")
Hi @Mark Markov,
Thanks for your help!
Nearly there, however it is always failing validation if PCI Affecting Change = Yes; even if CAB Approval is set to Accepted.
If PCI Affecting change = No then it flows through as expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure that you copy condition properly? With && operator. Because this condition must fails in only one situation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I've got the && in script correctly. Attached a screenshot of the setup screen so can check for me being dense! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, is this select lists custom fields?
If yes we ve got an error here :)
!(cfValues["PCI Affecting Change?"]?.value == "Yes" && cfValues["CAB Approval"]?.value != "Accepted")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah ha! I clearly missed that bit of useful information in my original post!
Latest script works perfectly, thanks for all your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You re welcome! If it helps you, please mark answer as accpeted. So that, other people will be able to find this answer easily for similar questions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.