Making a custom field required when another custom field radio button is checked

Filzah Aziz February 8, 2021

I would like for when i check the radio button with a value "Yes", and the other custom field to be mandatory. I did this as a behaviour in scriptrunner but it does not seem to work at creation.

Here is my code:

def customA= getFieldById("customfield_16191") // regular select custom field
def customB= getFieldById("customfield_14200") //radio button
//def customB_val= customB.getValue() as String

if (customB_vall == "Yes"){
customA.setRequired(true)
}

 

Would anyone have any idea what i'm doing wrong as i can't figure it out. Or perhaps this functionality is not possible on the create issue screen

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
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 8, 2021

This is absolutely possible.

I see some typos in your script.

Try like this:

def customA= getFieldById("customfield_16191") // regular select custom field
def customB= getFieldById("customfield_14200") //radio button
customA.setRequired(customB.value == "Yes")

Make sure this script is installed on the customB field so that it is executed with each change of value the radio button. 

Filzah Aziz February 8, 2021

Ah it should have been:

def customA= getFieldById("customfield_16191") // regular select custom field
def customB= getFieldById("customfield_14200") //radio button
def customB_val= customB.getValue() as String

if (customB_val == "Yes"){
customA.setRequired(true)
}

 

My script works, it was just that I had set it on the select custom field and not the radio button. But I would prefer using the script you provided as it was smoother upon execution. I could select and de-select the radio button as many times and it would be required or not required accordingly. Thanks for the help!

Suggest an answer

Log in or Sign up to answer