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.
Thanks in advance! :)
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:-
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.
2. When other options, including None, are selected from the Sample List, the Radio Button is visible as shown in the screenshots below:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
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')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.