Facing javascript problem while migrating from jira4.4 to jira5.X

Hi,

We are planning to migrate jira4.4 to jira5.X in our organisation. we have implemented some of the customized functionality on custom fields through javascript. our script is working fine in jira4.4 but its not working in jira5.x. we have tried the below sites information but still not able to get the solution for this.

https://developer.atlassian.com/display/JIRADEV/Custom+Fields+that+use+CSS+or+JavaScript+Web+Resources+in+JIRA+5.0

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

We would like to know is there any feature in Jira 5.x where the UI works like Jira 4.4. Can we acheive this by configuring any parameter in Jira 5.x.

Could you please suggest the solution for this.

3 answers

1 accepted

try with following code if the first alert came then you need to check your logic

<script type="text/javascript">	
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {		
		callFunction();
	});	
		callFunction();
function callFunction(){	
		alert("Test by Rambanam");
		$('#customfield_12661').focus(function(){
			 onFocusFunction();
		});
	}
	
	function onFocusFunction(){
	alert("in onfocus function");
			var testdefect = document.getElementById("customfield_12660");
			var w12 = testdefect.selectedIndex;
			var testvaldefect = testdefect.options[w12].text;
			var Maharashtra={"Select List": "-1", "Pune": "17890" ,"Nasik":"17158"};
			var Karnataka = {"Select List": "-1", "Hubli": "17159" ,"Banglore":"17160"};
			var phase={"Maharashtra": Maharashtra ,"Karnataka": Karnataka};
			var value = new Object();
			value = phase[testvaldefect];
			var count=0;
			defectIdval.innerHTML = "";
			for (var i in value)
			{
				defectIdval.options[count] =new Option(i,value[i]);
				count++;
			}
	}
});

</script>

Hi Rambanam,

Thanks for your help.

I have tried this code but once i log out and login again the alert was not working for the first time. Second time its working fine.

Thanks,

Jayasingh

on which screen you tried and where you added javascript? i mean in plugin or field configuration?

I have created a custom field named state and city. In city custom field i have added this script inside field configuration. I havent used any plugin.

Thanks,

Jayasingh

The fields are added in all the screens through out the issue. Field is present in Create / Resolve / Close / Edit screen.

those fields are in create screen?

the javascript doesnt workin create screen while issuetype on change.

add javascript as web resource module in plugin then it will work in all screens.

i posted link im my first answer to know how to add javascript in plugin

Hi Rambanam,

AWWWWWWWW........ Javascript Functionality working fine in jira5.0.7.

Thanks for your continuos support. The sample script helped us to resolve the long pending issue.

Now we set for the migration of jira from 4.4 to 5.0

Cheers,

Jayasingh

Jaya singh,

Threre is no way to configure any parameters to work javascript in 5.x as in 4.4 because the UI changed lot from 4.x to 5.x, so you have to change your script according to the 5.x UI

I added lot of javascripts on 5.x as specified in the following post and all are working fine,

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

But as you said it is not working, what your tring to achive and what error your getting
Mizan Community Champion Nov 19, 2012

Hi Rambanam ,

I have javascript which works when i place it in the announcement banner but it does not work when i embed it in a web resource plugin . Can you please help

refer my question here

Hi Rambanam,

We have tried two scenario using plugin

1. Added web resource in atlassian-plugin.xml, Added JIRA.Events.NEW_CONTENT_ADDED and ajax based javascript inside the js file, removed javascript from field configuration.
after installing this plugin we are getting the output as below:

Output: At the time of issue creation ,when we clicked on Create Issue Link, it is opening new page same as old version of JIRA 4.4, we are able to see all the projects in the project dropdown and in the issue type dropdown we are getting all the project specific issue types.Dropdown functionality was working fine. But dropdowns w.r.to Dashboard, Issues, Project is not working. They are in disabled mode

2. Added web resource in atlassian-plugin.xml, Added JIRA.Events.NEW_CONTENT_ADDED and ajax based javascript inside the js file as well as in field configuration.

Output: At the time of issue creation, we are able to see all the projects in the project dropdown and in the issue type dropdown we are getting all the project specific issue types

Thanks,

Jayasingh.

can you share your code in js file and check that is there any error throwing javascript using firebug on firefox or javascript console on crome

Hi Rambanam,

Here is my javascript.

<script language="JavaScript" type="text/javascript">
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
var defectIdval = document.getElementById("customfield_12661");
alert("Test by Jai");
AJS.$(function()
{
defectIdval.onfocus=function()
{

var testdefect = document.getElementById("customfield_12660");
var w12 = testdefect.selectedIndex;
var testvaldefect = testdefect.options[w12].text;
var Maharashtra={"Select List": "-1", "Pune": "17890" ,"Nasik":"17158"};
var Karnataka = {"Select List": "-1", "Hubli": "17159" ,"Banglore":"17160"};
var phase={"Maharashtra": Maharashtra ,"Karnataka": Karnataka};
var value = new Object();
value = phase[testvaldefect];
var count=0;
defectIdval.innerHTML = "";
for (var i in value)
{
defectIdval.options[count] =new Option(i,value[i]);
count++;
}
};

});
AJS.$(".defectIdval", context).live("change keypress keydown", onfocus);
});
</script>

Here we have created two custom fields as state and city. once the user select the field state as Maharastra. in city dropdown it should show pune and nasik. once user select state as Karnataka it should display Hubli and Banglore.

Thanks,

Jayasingh

you need to remove <script > tag from the js file

i.e remove <script language="JavaScript" type="text/javascript"> and </script> tags

Hi Rambanam,

Thanks for your input.

I have tried removing the script tags from the plugin but still no luck and i have tried all the alternative ways still not working.

Thanks,

Jayasingh

Hi Rambanam,

I have tried two ways as per your suggestion

1.Updating my script inside the plugin and left the field config blank

2. Updating my script inside the field config and adding the web resource and

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
});
inside the js file. But still i am not able to get the solution for this.
when i right click the create issue and open it on new tab or new window its working fine.

Hi Naren,

I have tried many alternative ways but still no luck :-(

Thanks,

Jayasingh

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

802 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you