Forums

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

Behaviour to make user populate 1 of 2 fields at least

Rob B
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.
February 6, 2024

User has to populate 1 of 2 specific fields.

Can this also produce and error at the top to advise this?

2 answers

1 accepted

1 vote
Answer accepted
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.
February 6, 2024

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')
}

 

Rob B
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.
February 7, 2024

Excellent! Thanks Pete!

1 vote
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2024 edited

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?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

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 Now
AUG Leaders

Atlassian Community Events