It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Javascript in field description not working when first opening create issue dialog

I am trying to use the following javascript to hide the javascript custom field and later add more functionality.

The strange thing is, it seems to work, but whenever I clear the browser cache and open the create issue dialog for the first time, it is not working.

<script type="text/javascript">

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

    hideFields();
  
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { 
        hideFields();
    });

    function hideFields() {

        // Hide 'JavaScript' field
        jQuery("#customfield_10201").closest('div.field-group').hide();

    }

    });
</script>

I have read almost every single thread about the topic here on answers.atlassian.com but I cannot figure it out.

13 answers

1 accepted

1 vote
Answer accepted

You either have to write your own web resource (plugin) or use the Live Fields functionality of the JJUPIN plugin from Kepler ROMInfo.

Hi, jQuery doesn't exist. Atlassian doesn't allow it. What I do is call AJS.$ instead. You need to prefix the jQuery calls with AJS.

That's not it. jQuery works just fine for me, but even with the following modifications you suggested it is still the same. When I first open the dialog, the field is rendered. If I close it and open it again then it disappears.

<script type="text/javascript">

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

	runJS();
	
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {   
        runJS();
	});

	function runJS() {

		// Hide 'JavaScript' field
		AJS.$("#customfield_10201").closest('div.field-group').hide();

	}

    });
</script>

It's AJS.$(function($) {...

I would check in Firebug or Chrome or any other developer tool you are using to see what Javascript error appears.

How can I make it run the javascript for all issue types but have separate actions per issue type? I don't want to write a plugin. Would a combination of announcement banner and field configurations do?

Simply put this in every description within a field configuration that needs this? You can create separate field configurations and map it to different issue types.

You can add it globally instead in the description of the custom field and not in the field configuration. Not sure if it'd be desired though as that would apply for everything.

The other idea is that the behaviour plugin does this out of the box.

Ok, I might have found the cause here:

If the preselected issue type does not have the javascript associated, then the whole thing does not work because the code never gets executed.

But the actual problem here is, that the code does not work if the preselected issue type is not setting binding the event JIRA.Events.NEW_CONTENT_ADDED.

We have 10 different issue types, but I only need to use it for 4, that means I have to configure it for all or for none =(

Hi, that's correct. Since you put it in the field configuration, it is part of the field configuration scheme. This is per issue type / project.

I really don't want to use another plugin for this and Jamie seems to be quite busy at the moment and does not maintain his plugins as well as he did in the past.

I would really prefer to figure out why this worked on JIRA 4.4.5 but is no longer working for JIRA 5.x

I was actually talking about ScriptRunner not the Behaviors plugin. People keep filing bug reports, but he does not seem to have the time to reply.

Regarding this issue, but where should I put it? The javascript I put in the description field no longer gets executed for the current issue type, but for the next one I choose.

The way Javascript is handled has changed in JIRA 5.x and hence the new events you have to listen to. Please put the javascript in the required places. As you said this is working.

It's not that Jamie doesn't meantime his plugins. He just has an issue with JIRA 5.1 and inline editing vs the behaviour plugin. That is all.

Do we have to restart JIRA after adding javascript for custom field configuration?

I have added js for making a multi select custom field auto render. It is not working if I check in Search for that field after adding the javascript. Please guide. I have just started with JIRA

No you don't have to restart

We have the same issue

when I change the issuetype (so I change the fieldconfiguration because the other issuetype has another configuration) the javascript doesn t work.

you need to load your javascript in a plugin as webresource module, check this

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Off-topic

Atlassian Community Guide to A+ Articles

Stop: Articles and permission Article-writing permissions are given to Leaders, Marketplace Vendors, Solutions Partners, Atlassian Team members, and those who are Level 4 + above. But for any aspir...

94 views 9 11
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you