JQuery script to clear field worked in JIRA 4 but does not in 6

The script empties Assignee if another field changes, in this case the custom field Location

<script type="text/javascript">

jQuery(document).ready(function() {

var location_fld = document.getElementById("customfield_10505");

var assignee_fld = document.getElementById("assignee");

location_fld.onchange = function(){

assignee_fld.value = "";

}

});

</script>

I am a novice at modifing JIRA with scripts so please don't provide me a geeky response that I can't follow. This is a new copy of JIRA on a new server, not an upgrade, so maybe a missing plugin or configuration is at fault.

4 answers

If you are modifying JIRA templates to insert your own scripts, you may need to encounter "geeky" answers...

Instead of using jquery, use AJS, atlassian's wrapper.

AJS.$(document).ready(function() {

Second, use the page source view (ctrl+U in chrome) to verify that the IDs are both still valid.

I'm afraid I'm on a timelime and JIRA is not my normal responsibility. I don't have the time to learn AJS, when I finish this project I will probably not use JIRA for some time as my job is Unix/Linux support.

your code also seems correct but you have to include that in following event

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
//your logic here
});

you can try with following code

&lt;script type="text/javascript"&gt;  
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
		clearAssignee();
	});
		clearAssignee();
function clearAssignee(){
	$('#customfield_10505').change(function() {	
		$('#assignee').val('');
	}):
		
	}

});
&lt;/script&gt;

the bind event is used here to execute the JavaScript on popup's(ex. create issue, transition, edit issue popup's ).

yes, it should be added in description of custom field in field configuration

I had seen the JIRA.bind... on responses to other questions but did not know what it was for. Anyway I applied it but the problem remains. Do these scripts still go in the description field?

The code was breaking the maintenance page for Custom Fields so I removed it. I will need to readdress this later when I have the time. Thanks for your help.

Is there a good reference document to learn these things?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

23,104 views 2 7
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