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

jayasingh November 19, 2012

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

2 votes
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.
December 4, 2012

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>

jayasingh December 5, 2012

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

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.
December 5, 2012

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

jayasingh December 5, 2012

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

jayasingh December 5, 2012

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

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.
December 5, 2012

those fields are in create screen?

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.
December 5, 2012

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

jayasingh December 12, 2012

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

1 vote
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.
November 19, 2012

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
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.
November 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

jayasingh November 19, 2012

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.

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.
November 20, 2012

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

jayasingh November 21, 2012

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

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.
November 21, 2012

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

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

jayasingh December 4, 2012

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

jayasingh December 4, 2012

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.

0 votes
Naren
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.
November 19, 2012
jayasingh December 4, 2012

Hi Naren,

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

Thanks,

Jayasingh

Suggest an answer

Log in or Sign up to answer