How to include some JavaScript for a jira custom field?

I tried to add some JavaScript inside a custom field description and it worked well inside the custom field editor.

Still, it seems that Jira stripped my javascript from the description when it was displayed in the issue UI (as apposed to the admin area, where it did not).

So, I would say this is a bug, now the question is how to workaround this and have my code executed.

3 answers

In complement to my previous intervention, I have just found how a workaround to my issue:

<script type="text/javascript">
(function($) {  
        do stuff...
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        do stuff again... 
    // ------------------ Below the new line
    $(selector_of_the_element_to_modify).live("click", do stuff agin...)

I thought the .live would be sufficient, but the rest of the code provided by John Burns is still required: the call to .toInit and .bind handles the case when the create popup opens with the CF already shown, and the call to .live handles the case when the project/issue type needs to be changed to display the CF

Not sure how this can be used to do something else than adding handlers to specific elements, though

0 votes

Have you included it in the correct field configuration? Editing description under custom fields is not enough.

I think it should be enough, as the description I entered does appear inside the Create/Edit screen, it is updated when I modify it but it does not contain the script part `<script>...</script>`. Which, by the way is included in the list of custom fields in the admin. I think this is related to the fact that in new jira (5.x), the Create/Edit screens are created from JSON instead of being rendered on the server side.

Can you try adding it in the field configuration and see how it works? I can certainly find mine in the create/edit screens. Even on Create/Edit, rendering is done on server side.

I tried, no change the script section is removed but the rest is kept.

Try using this template:

&lt;script type="text/javascript"&gt;
(function($) {   
        do stuff...
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        do stuff again...  

I tried and the code does not reach the UI or Create/Edit issue. Still, anything that is outside the script tags does reach. Are you sure that you tested this with Jira 5.2?

Yes, I am on 5.2, and it works in my instance. You might need to open a support ticket on this one.

I am retrying now on a test instance by enabling the safe mode, maybe there is somethiing that does this.

John's answer worked for my case (Jira 5.0.7, trying to set onclick actions for a CF), thank you very much John !

Still there is a case when it is not enough: my CF is only available for one issue type (New feature). When the Create popup opens with another issue type selected and I change it to New Feature, the script seems not to run. Not a real problem for my case, I'll eventually try to find a workaround


did you find a workaround? I have currently the exactly same issue and for me it _is_ a problem ;-)

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,757 views 18 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