Hide CustomField type radio buttons

Kevin Bruneau March 10, 2023

Hi guys!

I need to hide a field being radio buttons type depending on the value selected from another field. The problem that I have is that I can't seem to hide the radio button field. It works with every other ones (They aren't radio buttons fields) except that one. Also, it doesn't have a 'customfield_id like the other ones. Only the options has one. I also tried using the option id's, but no result. Btw, it's a behaviour that I'm trying to add.


Here is my code :

def IT_Security_Risk_Field = getFieldById('customfield_26305') // SEMS IT Security Risk Assessment Questionnaire
def Result_IT_Security_Field = getFieldByName('customfield_25703') // Result of IT Security Questionnaire

if(IT_Security_Risk_Field.getValue() == 'Not Required'){
Result_IT_Security_Field.setHidden(true)
}
else{
Result_IT_Security_Field.setHidden(false)
}

 

Here is the 'inspect' view of the field. As you can see, the options has their own customId's, but even that doesn't work. Screenshot 2023-03-10 105740.png

 

Thanks in advance! :)

1 answer

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 11, 2023

Hi @Kevin Bruneau

For your requirement, you must create a Server-Side Behaviour for the  IT_Security_Risk_Field.

To ensure the Server-Side Behaviour takes effect when the value has been selected for that field, you must declare the field using:-

def sampleList = getFieldById(fieldChanged)

Below is an example of a fully working code for your reference:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()

def sampleRadioButton = getFieldByName('Sample Radio Button')
sampleRadioButton.hidden = false

if (sampleListValue == 'Option 1') {
sampleRadioButton.hidden = true
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

This Server-Side Behaviour above has been added for the Sample List field, and when Option 1 has been selected from the Sample List field, the Radio Buttons will be hidden. 

For all other options, the Radio Button will be visible.

Below are a couple of test screenshots for your reference:-

1. The Radio Button is hidden as expected when Option 1 is selected from the Sample List.

test2.png

2. When other options, including None, are selected from the Sample List, the Radio Button is visible as shown in the screenshots below:-

test1.png

test3.png

test4.png

test5.png

 

I hope this helps to answer your question. :-)

Thank you and Kind regards,
Ram

Kevin Bruneau March 13, 2023

Hi Ram! :)

Thanks for the reply!

I tried that, and it doesn't work :(

It's almost as if the radio button field has no 'name'/'id' for some reason.

With every other fields it works (They have a customfield_id)

Here is what I tried : 

(The customfield_26306 is the field having the list in which we can choose 'Not Required')

script.png

Like Millicent likes this
Kevin Bruneau March 13, 2023

field inspect.png

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 13, 2023

Hi @Kevin Bruneau ,

From the latest screenshots you have shared, it appears you are using a pretty old version of ScriptRunner.

Please upgrade to the latest release, i.e. 7.12.0 an try it once again.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events