Does JIRA Server 7.3.3 supports JavaScript for Custom Fields successfully?

Vivek Pagare June 28, 2017

We've been facing some issues on the issue creation. we have many custom fields that are embedded through JavaScripts. However, sometimes the create issue scheme works perfectly and sometimes it doesn't.

Any info on why this is happening?

2 answers

1 vote
Stefan Arnold
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2017

I think you embedded the javascript in the custom field description in field configuration, right?

Iam also using javascript in summary description. the important thinks you have to look for are the "events" and the field configuration schemes.

Example: If you want your javascript executed for a customfield in screen for project X (each issuetype). you have implemented the javascript in the field configuration for that project. When you open create dialog and the project X is already selected the correct field configuration is loaded and the javascript is executed.
If at that moment Project Y is selected the field configuration of Project Y is loaded, if you switch to project X it will in any kind sure load the field configuration of project X but it wont execute the javascript of that X field configuration.
Iam not sure why its doing this.
So what i did is to embed my javascript in each field configuration (yes that can be alot of work, we currently have 35 different field configurations) and in my code i check the project and issuetype and then i execute whats necessary.

in this example iam hidding the summaryfield and prefill it. i override the "randomtext" the with a groovy script that is executed in create transition postfunction.

<script type="text/javascript">
AJS.$(document).ready(function(event, dialog) {
 console.log("Executing document.ready");
 checkIssueType();
});
AJS.$(document).bind('dialogContentReady', function(event, dialog) {
 console.log("Executing document.bind.dialogContentReady");
 checkIssueType();
});

function checkIssueType(){
    var projectField = AJS.$('#project-field').val();
 var issueTypeField = AJS.$('#issuetype-field').val();
 console.log("Project: " + projectField);
 console.log("Issuetype: " + issueTypeField);
var summaryField=AJS.$("#summary").parent();

 if(projectField == "Project X (XXX)" && issueTypeField != "AnyIssuetype (AIT)")
 {
  //to escape this error "summary required"
  AJS.$("#summary").val("randomtext");
  summaryField.hide();
 }
    else if(projectField == "Project Z (ZZZ)" || projectField == "AnotherIssuetype (AIT)"){
  //to escape this error "summary required"
  AJS.$("#summary").val("randomtext");
  summaryField.hide();
}

else{
  if(AJS.$("#summary").val() == "keine Aenderung notwendig")
   AJS.$("#summary").val("");
  summaryField.show();
    }
};
</script>

Maybe this gets you an idea what you can do to solve your problem

Vivek Pagare June 29, 2017

Hi Stefan, Thanks for your detailed guidance, yes we embedded the javascript in the custom field description in field configuration. But we're working in only one project but ofcourse different issue types. So would using a plugin such as ScriptRunner solve this problem? Please advise

Stefan Arnold
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2017

If you have different field configurations for that issuetypes its still the same problem. the javescript has to be in each of them

The question is what you are trying to achieve.

If you want someting like dynamically prefilled custom fields in create screen then i dont believe there is a way to achieve this with scriptrunner. 
If you want to fill some customfields immediately after the issue is created then sure you could use a scriptrunner script in the create transition as postfunction.

0 votes
Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2017

JIRA does not support javascript in customfields.

If they aren't working, are they throwing errors in the browser console? Do they work in the "full page create" operation, or do they work in the dialog?

We need more information to help you at all.

Vivek Pagare June 29, 2017

Hi Steven, Thanks for your prompt response.

Yes we are getting errors in the browser console, We want to show and hide fields based on the value selected from a custom select list. These function were working better in the previous versions of JIRA, but in this version it's not working as it is supposed to be.

Please advise :)

Suggest an answer

Log in or Sign up to answer