User has to populate 1 of 2 specific fields.
Can this also produce and error at the top to advise this?
Hi @Rob B
Yes, using a Behaviour server-side script, you can make 2 fields co-required. I.e. at least A or B must be populated.
Here is how you might do that.
1) In field A, add a server-side script
def fieldA = getFieldByName('A Name')
def fieldB = getFieldByName('B Name')
fieldB.setRequired(!fieldA.value)
2) in field B, add a server-side script
def fieldA = getFieldByName('A Name')
def fieldB = getFieldByName('B Name')
fieldA.setRequired(!fieldB.value)
What this does is tie whether 1 field is required on the value of the other. If there is a value in field A, field B is no longer required. But when field A is empty, then Field B is required.
And vice versa.
When both fields are empty, both fields will appear as required. But the second you populate one of them, the other will not be required anymore.
If the user attempts to submit while both are empty, they will both be flagged in red with "this field is required".
If you want, you can add this to both scripts if you want to be more explicit when both fields are empty:
if(!fieldB.value && !fieldB.value){
fieldA.setError('Either field A or field B must be filled in')
}
Excellent! Thanks Pete!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Rob B
Are these fields that need to be populated at all points during the issue lifecycle? If so, you could simply set them as Required in the Field Configuration.
Are the fields that need to be filled in during a status transition? In that case you could add a Validator to the transition.
Why are you asking specifically for a Behavior solution?
You said 1 of 2 fields. Does that mean you want only one or the other populated but not both? Is there some additional criteria to determine which should be populated?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline 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.