Javascript in JIRA : set values to fields according value specified in a listbox

Christophe Leite September 16, 2013

Hi all,

I wonder if it was possible to set values to fields according the value you choose in a listbox.

Example :

I've got a listbox list1, another one list2 and a textbox text1.

  • list1 contains 'value1', 'value2' and 'value3'
  • list2 contains 'valueA', 'valueB' and 'valueC'
  • text1 is empty

Is this possible to write a simple little script to command the display of both list2 and text1 according to the value selected in list1 : for example, if I choos 'value1' in list1, I would like to have 'valueB' automatically selected in list2 and text1 filled with 'value1' ?

Have you ever write a such script ? could you forward me to help ?

Thanks a lot,

Christophe

4 answers

1 accepted

1 vote
Answer accepted
RambanamP
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.
September 16, 2013

@Chris,

again i am giving solution :)

i suggest to load javascript as webresource module in aplugin

check this for reference https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen

<script type="text/javascript"> 
jQuery(document).ready(function($) { 
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { 
callHideShowFunction();
});
callHideShowFunction();
function callHideShowFunction(){
        showHideSelectList();  
	//list1 onchange		
    $('#customfield_10903').change(function() { 
        showHideSelectList();
    });
}
function showHideSelectList(){ 
		//list1 field
    var firstListValue=$.trim($("#customfield_10903 :selected").text()); 
		//list2 field
		$("#customfield_10902").closest('div.field-group').hide();
		//text box
		$("#customfield_10904").closest('div.field-group').hide();
    if( firstListValue == "Yes" ){       
        $("#customfield_10902").closest('div.field-group').show();
		//select list 2 field value
		$("#customfield_10902 option").each(function() {
			if($(this).text() == 'valueB') {
				$(this).attr('selected', 'selected');            
			}                        
		});
				
		$("#customfield_10904").closest('div.field-group').show();
		//set text box value with list1 selected value(here i am adding selected text not option id)
		$("#customfield_10904").val(firstListValue);
    }else {      
        $('#customfield_10902').val('');
        $("#customfield_10902").closest('div.field-group').hide();
		//before hiding clearing field
		$("#customfield_10904").val('');
		$("#customfield_10904").closest('div.field-group').show();
    }
}
		
});
</script>

i hope atleast it will work as you expected!!

1 vote
darylchuah
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 16, 2013

Hi Chris

I believe script runner plugin will be able to help you on this. You may check with the plugin vendor, Jamie Echlin regarding on this.

Hopefully it helps cheers :)

0 votes
ahmet tetik January 22, 2015

Hi.  how I will do  for user session 

0 votes
Christophe Leite September 16, 2013

But it is in a same issue screen (when I create an issue).... not in the workflow, using transitions...

Suggest an answer

Log in or Sign up to answer