Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to load java script in jira view/edit issue screen

Venkateswara Kumar December 3, 2018

Hi, 

I wrote java script in description field for custom fields dependency enumeration  in jira, but the problem it is replicated in create issue screen, not in "view issue screen".
If modified the options in custom dropdown once has created , my javascript is not loading on that View issue screen page.Kindly suggest on this!!

1 answer

0 votes
Nic Brough -Adaptavist-
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.
December 3, 2018

Javascript hacks are really not recommended as you have to make them work in many different places and that means hacking different code into many places.  You are going to need to inject the javascript everywhere, and this can only really be done by using the announcement banner.  But you should expect the ability to run javascript there to go away eventually.

I'd suggest doing your "enumeration" properly - with add-ons that handle the code for you, or, better, fields that do the work without bodging hacks in.

Venkateswara Kumar December 5, 2018

Thanks alot Nic for your valuable information,

can we make it, for  particular functionality using Announcement banner? 
Even though using Add-on's , should not able put different names for three individual dropdowns in dependency enumeration , so finally i have implemented using javascript 
and achieved it, working fine while creating issue.
but the problem is that, java script is not loading in once issue has created i.e; view issue screen.

Kindly suggest on this.

Nic Brough -Adaptavist-
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.
December 5, 2018

It's impossible to say without seeing what you're injecting and how you've tried to make it work.  Have you tried to deal with all 9 places you might have to "enumerate" your field, or are you only trying to deal with the 4 main places you need to do it? 

(I should also point out that I'm not a Javascript coder - I don't use it much, other than reading stuff I'm going to remove from Jira so it can be done properly instead)

Venkateswara Kumar December 12, 2018

Hi Nic, 
Please find below code for dependency enumeration.
It is working in create,edit  issue screen and not in view issue screen once has created i.e; on the screen.
Please do needful

<script type="text/javascript">
var Country1 = document.getElementById("customfield_10101");
var State1 = document.getElementById("customfield_10102");
if(Country1.options[Country1.selectedIndex].text=="None"){
for(i=1;i<6;i++){
State1[i].style.display='none';
}
}


Country1.onchange=function() {

if(Country1.options[Country1.selectedIndex].text=="None"){
for(i=1;i<6;i++){
State1[i].style.display='none';
}
}
if(Country1.options[Country1.selectedIndex].text=="Pakisthan"){
for(i=1;i<3;i++){
State1[i].style.display='none';
}
for(i=3;i<6;i++){
State1[i].style.display='block';
}
}

if(Country1.options[Country1.selectedIndex].text=="India"){
for(i=1;i<3;i++){
State1[i].style.display='block';
}
for(i=3;i<6;i++){
State1[i].style.display='none';
}

}
}
</script>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events