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

Fabian Meier Sep 05, 2012

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
Fabian Meier Apr 14, 2013

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

0 votes
Harry Chan Sep 05, 2012

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.

Fabian Meier Sep 05, 2012

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>

Harry Chan Sep 05, 2012

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.

0 votes
Fabian Meier Sep 05, 2012

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?

0 votes
Harry Chan Sep 05, 2012

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.

0 votes
Harry Chan Sep 05, 2012

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.

0 votes
Fabian Meier Sep 05, 2012

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.

0 votes
Fabian Meier Sep 05, 2012

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 =(

0 votes
Harry Chan Sep 05, 2012

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.

0 votes
Fabian Meier Sep 05, 2012

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

0 votes
Fabian Meier Sep 05, 2012

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.

0 votes
Harry Chan Sep 05, 2012

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.

0 votes
meena bhujang Aug 29, 2013

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

Technical Services Feb 09, 2014

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.

Rambanam Prasad Feb 09, 2014

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase

Friday Fun: What's your best vacation planning hack?

Let's face it, work can be challenging but fulfilling, especially when you enjoy the challenges thrown at you.  However for me, nothing compares to going on vacation (or holiday as some of you m...

537 views 26 4
Join discussion

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