How do I display a field based on the values of a Single select list in JIRA?

Karanpreet Kaur April 1, 2016

Hello, I am have been trying to display a field based on the value of a single select list using the example mentioned in the page below, but it doesnt work.

https://confluence.atlassian.com/jirakb/how-to-display-a-field-based-on-another-field-s-selection-649921383.html

I read that it can be achieved using Behaviors in ScriptRunner?

Can I get some more information on how this could be done?

2 answers

1 vote
JamieA
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.
April 3, 2016
0 votes
Steven F Behnke
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.
April 1, 2016

I wrote my own updated version of that script, I can provide it – 

<script type="text/javascript">
/*---------
   Use Case
-----------
   Only show targetField when the changingField is set to
   desiredValue.
-----------
   This is using basic javascript and the jquery library
   provided by atlassian. This should be within the Field
   Description, within the Field Configuration.
   The jQuery can be accessed using the AJS.$ wrapper.*/
 
    //Obtain the first field by ID
    changingField = document.getElementById('customfield_13322');
     
    //Start our process if the field is present
    if (changingField) {
         
            //Desired value to show the target field
            desiredValue = '10939'
  
            //Obtain the second field by ID
            targetField = document.getElementById('customfield_13708');
  
            // This first if-statement will hide the target field immediately, unless the default value is set to our desired value
            // Hide the target field's container if changing field isn't set the desired value
            if (changingField.value != desiredValue) AJS.$(targetField).parent().hide()
  
            // onchange runs when a select field changes. Basic logic here shows it for desired value, hides it for all else
            // Be sure to set the field to nothing when using the else clause to hide the field container, otherwise you'll still submit data
            changingField.onchange=function() {
                if (this.value == desiredValue) {           
                    AJS.$(targetField).parent().fadeIn( 200, "jswing" )
                    } else {
                        targetField.value='';
                        AJS.$(targetField).parent().fadeOut( 200, "jswing" )
                      }
            }
    }
 </script>
Steven F Behnke
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.
April 1, 2016

Unfortunately I haven't done this specific task with ScriptRunner Field Behaviors – You can look for hints or examples on the documentation page: https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html#_examples

Karanpreet Kaur April 21, 2016

Can you please advise how this can be done using a Cascading Select. I am not too familiar with java script. Might need to get sometime to learn more about JS.

Suggest an answer

Log in or Sign up to answer