Jira Script-runner disablele custom field based on radio value

Qi Jiang August 28, 2017

I have a radio button with value yes, no, two multiline text field A, B. Wonder if I can following:

If radio button value == Yes

A enabled, B will be disabled

If radio button value == No 

A disabled, B will be enabled

 

I am doing this in behavior script

1 answer

1 accepted

1 vote
Answer accepted
Jenna Davis
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.
August 28, 2017

You can do something like this:

def radio = getFieldById(getFieldChanged())
def fieldA = getFieldByName("FieldA")
def fieldB = getFieldByName("FieldB")

def selected = radio.getValue() as String

if(selected == null) {
fieldA.setFormValue(null)
fieldA.setHidden(true)
fieldB.setFormValue(null)
fieldB.setHidden(true)
}
if(selected == "A"){
fieldB.setFormValue(null)
fieldB.setHidden(true)
fieldA.setHidden(false)
}
if(selected == "B"){
fieldA.setFormValue(null)
fieldA.setHidden(true)
fieldB.setHidden(false)
}

This will need to be set up on your radio button field. It currently is set up to disable (set hidden and set to null) both fields if 'None' is selected. You can change this by modifying the first 'if' if you'd like. If you need help with this or anything else, let me know. :)

Regards, 

Jenna

Parvaneh Zand
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.
July 19, 2020

This was very helpful! Thank you @Jenna Davis 

minaxijoshi3101 February 14, 2023

How can we disable particular custom field instead of hiding that?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events