Problem running JS from the 'Description' of a field in JIRA 5.2.5's Create Issue screens

We've been using a little bit of JS in one of our field Descriptions for a while now:

<script type="text/javascript">jQuery(document).ready(function($) { ... });</script>

This particular field only appears on one of our Issue Types, so the code is expected to run only when creating an Issue of that Type.

Following the upgrade from JIRA4 to JIRA5, I've discovered that this is no longer reliable: it only seems to execute if the 'Create Issue' popup opens with the relevant Issue Type already selected. If another Issue Type is selected and you change to the one we're interested in, the code doesn't run.

(I suspect this may have been a problem in JIRA4 too, but we got around it by the simple expedient of not allowing the user to change the Issue Type from the Create Issue screen...not an option in JIRA5 so far as I can see.)

Now, I'm not particularly familiar with JS so I'm entirely happy to accept that the above fragment of code isn't the correct way to do this :-) But I haven't been able to find anything else that works at all, never mind works with the JIRA5 Create Issue popup.

Can anyone help, please?

2 answers

1 accepted

Thanks, that's exactly what I was looking for! :-) I've had to move all the JS to the Description of the 'Summary' field, since it's the only field which appears on all the issue-types, but that's fine.

I've found one slightly odd bit of behaviour, though - before I raise this as a bug, can anyone confirm what I'm seeing, please?

I have some code in the Summary's Description which is run like this:

<script type="text/javascript">
AJS.$(document).ready(function($) {

runJS();

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

function runJS() {
... do stuff here ....

}

});

</script>

This all works perfectly from both the Create and Edit Issue screens - unless I cancel the popup rather than confirming it. If I do this, then I see the following behaviour:

1. If I cancel the Create Issue popup, any other popup which wants to run JS will not open; instead I just get the 'busy' spinner in the middle of the screen, and it stays there indefinitely. The Create Issue popup will still open, but nothing else. The spinner can be cleared by either hitting Escape or refreshing the browser, but the problem will remain until I either refresh the current page or go to another one.

2. If I cancel the Edit Issue popup, whilst all other popups (Create, Edit, transitions) will open without problems, none of the JS on their fields will now run. This too can be resolved by refreshing or going to another page; it can also be cleared by re-opening the Edit Issue popup and closing it with 'Update' rather than 'Cancel'.

If this is a bug then I'll raise a support issue, but if it's just me doing something dumb then I'd be very grateful for some assistance in fixing it :-)

Located the problem. It turns out I had a small error in my JS which was causing the script to terminate unexpectedly. For some reason this then killed every single script on the page until it was refreshed.

Another bit of JS is suffering from the problem now. We have this bit of code in the Description for a few multi-select-list fields:

<script type="text/javascript">
(function($){
new AJS.MultiSelect({
element: $("#customfield_15702"),
itemAttrDisplayed: "label",
errorMessage: AJS.params.multiselectComponentsError
});
})(AJS.$);

</script>

(This converts the normal multi-select list into a Components/Version-style combo-box.)

Once again it's fine when the popup opens, but changing the Issue Type kills it and the field reverts to the default list.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,550 views 15 21
Read article

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