Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-33768

Jira macro insert button is disabled after naming a Jira custom field "Length" for any linked Confluence instance

    XMLWordPrintable

Details

    Description

      NOTE: This bug report is for Confluence Server. Using Confluence Cloud? See the corresponding bug report.

      The problem:

      The Insert button in JIRA Issue Macro is greyed out and a Javascript error is thrown in the browser console:

      Uncaught RangeError: Invalid array length batch.js:7545
      e batch.js:7545
      AJS.Editor.JiraConnector.Panel.Search.AJS.$.extend.prepareColumnInput batch.js:7545
      AJS.Editor.JiraConnector.Panel.Search.AJS.$.extend.loadMacroParams batch.js:7545
      (anonymous function) batch.js:7545
      currentXhr.AppLinks.makeRequest.success batch.js:7534
      fire batch.js:1077
      self.fireWith batch.js:1195
      done batch.js:7540
      callback
      

      The following appears on the screen:

      This error refers to the following JavaScript:

      try {
      /* module-key = 'confluence.extra.jira:dialogsJs', location = '/jira/searchpanel.js' */
      AJS.Editor.JiraConnector.Panel.Search=function(){this.jql_operators=/=|!=|~|>|<|!~| is | in /i};AJS.Editor.JiraConnector.Select2=AJS.Editor.JiraConnector.Select2||{};AJS.Editor.JiraConnector.Select2.getKeyColumnsSelectedOptions=function(b){var a=[];var d=b.select2("data");for(var c=0;c<d.length;c++){a[c]=d[c].id}return a.join()};AJS.Editor.JiraConnector.Panel.Search.prototype=AJS.$.extend(AJS.Editor.JiraConnector.Panel.Search.prototype,AJS.Editor.JiraConnector.Panel.prototype);AJS.Editor.JiraConnector.Panel.Search.prototype=AJS.$.extend(AJS.Editor.JiraConnector.Panel.Search.prototype,{defaultColumns:"key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution",DEFAULT_MAX_ISSUES_VAL:20,MAXIMUM_MAX_ISSUES_VAL:1000,MINIMUM_MAX_ISSUES_VAL:1,title:function(){return "Search"},init:function(a){a.html('<div id="my-jira-search"></div>');var f=this;var b=AJS.$("#my-jira-search");this.container=b;var h=function(){b.children(":not(div.jira-search-form)").remove()};var e=function(){AJS.$("input.text",b).enable();AJS.$("button",b).enable()};var l=function(){AJS.$("button",b).disable();AJS.$("input.text",b).disable()};var i=function(n){h();f.disableInsert();if(n){f.selectedServer=n}if(f.selectedServer.authUrl){l();var m=f.createOauthForm(function(){h();e()});b.append(m)}else{e();AJS.$(".search-help").show()}};this.authCheck=i;var g=function(x){var m=x&&x.searchValue;var o=x&&x.serverName;if(m){AJS.$("input:text",b).val(m)}if(o&&o!=this.selectedServer.name){var y=AJS.Editor.JiraConnector.servers;var q=false;for(var r=0;r<y.length;r++){if(y[r].name==o){AJS.$('option[value="'+y[r].id+'"]',b).attr("selected","selected");AJS.$("select",b).change();q=trueBest Regards
      
      Alisha Dash
      Atlassian Cloud Support.eak}}if(!q){c(AJS.Meta.get("is-admin"))_*Edit*: removed previous email thread (Amanda)_urn}}if(this.currentXhr&&this.currentXhr.readyState!=4){return}var p=m||AJS.$("input",b).val();if(AJS.Editor.JiraAnalytics){var w=AJS.JQLHelper.checkQueryType(p);if(w){AJS.Editor.JiraAnalytics.triggerSearchEvent({type:w,source:"dialog"})}}var s=function(C,E,D){var B=b.find("#jiraIssueColumnSelector");var A=B.val()&&B.val().join();AJS.$("select",b).disable();l();f.lastSearch=C;f.createIssueTableFromUrl(b,f.selectedServer.id,"/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery="+encodeURIComponent(C)+"&returnMax=true&tempMax=20&field=summary&field=type&field=link",f.selectHandler,f.insertLinkFromForm,function(){f.addDisplayOptionPanel();f.loadMacroParams(A);f.bindEventToDisplayOptionPanel(true,x);f.enableInsert()},function(F){f.addDisplayOptionPanel();f.loadMacroParams(A);f.bindEventToDisplayOptionPanel(false,x);f.updateTotalIssuesDisplay(F);f.checkAutoSelectColumns();x&&x.isAutoSearch&&f.focusForm()},function(F){f.disableInsert();if(F.status==400){if(D){D()}else{AJS.$("div.data-table",b).remove();f.warningMsg(b,AJS.format("The JIRA server didn\'\'t understand your search query. If you entered JQL, please ensure that it\'\'s correctly formed. If you entered an issue key, ensure that it exists and you have permission to view it. {0}",Confluence.Templates.ConfluenceJiraPlugin.learnMore()))}}else{AJS.$("div.data-table",b).remove();f.ajaxError(F,i)}x&&x.isAutoSearch&&f.focusForm()},true)};if(AJS.JQLHelper.isFilterUrl(p)){var n=decodeURIComponent(p);var v=AJS.JQLHelper.findServerIndexFromUrl(n,AJS.Editor.JiraConnector.servers);if(v!=-1){var t=AJS.Editor.JiraConnector.servers[v].id;AJS.$('option[value="'+t+'"]',b).attr("selected","selected");AJS.$("select",b).change();var z=AJS.JQLHelper.getFilterFromFilterUrl(n);if(z){AJS.$("input",b).val(z);s(z)}else{h();f.warningMsg(b,AJS.format("The JIRA server didn\'\'t understand your search query. If you entered JQL, please ensure that it\'\'s correctly formed. If you entered an issue key, ensure that it exists and you have permission to view it. {0}",Confluence.Templates.ConfluenceJiraPlugin.learnMore()))}}else{h();f.disableInsert();c(AJS.Meta.get("is-admin"))}}else{if(AJS.JQLHelper.isIssueUrlOrXmlUrl(p)){var n=decodeURIComponent(p);var u=AJS.JQLHelper.getJqlAndServerIndexFromUrl(n,AJS.Editor.JiraConnector.servers);if(d(u)){AJS.$("input",b).val(u.jqlQuery);s(u.jqlQuery,false,null)}}else{if(p.match(f.jql_operators)){s(p,false,null)}else{if(AJS.JQLHelper.isSingleKeyJQLExp(p)){s("key = "+p,true)}else{if(AJS.JQLHelper.isMultipleSingleKeyJQLExp(p)){s("key in ("+p+")",true)}else{s('summary ~ "'+p+'" OR description ~ "'+p+'"',false,null)}}}}}};this.doSearch=g;f.addSearchForm();var d=function(m){var n;if(m.serverIndex!=-1){AJS.$('option[value="'+AJS.Editor.JiraConnector.servers[m.serverIndex].id+'"]',b).attr("selected","selected");AJS.$("select",b).change();if(m.jqlQuery.length==0){h();f.errorMsg(b,"The JIRA server didn\'t understand your search query. If you entered JQL, please ensure that it\'s correctly formed. If you entered an issue key, ensure that it exists and you have permission to view it. {0}")}else{n=m.jqlQuery}}else{h();f.disableInsert();c(AJS.Meta.get("is-admin"))}return n};f.processJiraParams=d;var c=function(m){var o=Confluence.Templates.ConfluenceJ...type"};var e=function(j){var p=[];var s=AJS.$("#jiraIssueColumnSelector");var l="";var o="";var r;for(var k=0;k<j.length;k++){var q=j[k];if(q.navigable){if(d[q.id]){q.id=d[q.id]}if(q.custom===true){r=q.name.toLowerCase()}else{r=q.id.toLowerCase()}var n=AJS.template("<option value='{value}'>{displayValue}</option>");p[r]=q.name;if(AJS.$.inArray(r,b)<0){l+=n.fill({value:r,displayValue:q.name})}}}p.key="Key";for(var k=0;k<b.length;k++){var h=AJS.template("<option selected='true' value='{value}'>{displayValue}</option>");r=b[k].toLowerCase();if(p[r]!=null){o+=h.fill({value:r,displayValue:p[r]})}}var m=o+l;s.html(m);s.auiSelect2({width:"415px",containerCssClass:"select2-container-jira-issue-columns"});AJS.Editor.JiraConnector.Panel.Search.jiraColumnSelectBox=s};if(f.columns&&f.columns.length>0){e(f.columns)_*Edit*: removed previous email thread (Amanda)_urn}this.retrieveJson(f.id,"/rest/api/2/field",function(h){if(h&&h.length){f.columns=h;e(f.columns)}})},expandDisplayOptPanel:function(){var b=AJS.$(".jql-display-opts-overlay");var c=b.height();var d=40;b.css("top","");var a=-(c-d);b.css("bottom",a+"px");b.animate({bottom:0},500)},minimizeDisplayOptPanel:function(){var a=AJS.$(".jql-display-opts-overlay");a.css("top",a.position().top+"px");a.css("bottom","");a.animate({top:420},500)},disableAutoSelectColumns:function(){AJS.Editor.JiraConnector.Panel.Search.jiraColumnSelectBox.auiSelect2("enable",false)},enableAutoSelectColumns:function(){AJS.Editor.JiraConnector.Panel.Search.jiraColumnSelectBox.auiSelect2("enable",true)},checkAutoSelectColumns:function(){if(AJS.$("#opt-table").prop("checked")){this.enableAutoSelectColumns()}else{this.disableAutoSelectColumns();this.enableInsert()}},bindEventToDisplayOptionPanel:function(f,h){var d=this;var b=AJS.$(".jql-display-opts-close, .jql-display-opts-open"),c=AJS.$(".jql-display-opts-overlay"),i=AJS.$(".jql-display-opts-inner .radio"),a=AJS.$("#my-jira-search input:checkbox[name=jira-issue-all]"),e=AJS.$("#my-jira-search input:checkbox[name=jira-issue]");var g=AJS.$("#jira-maximum-issues");g.on("blur keyup",AJS.Editor.JiraConnector.Panel.Search.prototype.validateMaxIssues);c.css("top","420px");b.click(function(j){j.preventDefault();if(AJS.$(this).hasClass("disabled")){return}var k=AJS.$(this).hasClass("jql-display-opts-open");if(k){d.expandDisplayOptPanel();jQuery(this).addClass("jql-display-opts-close");jQuery(this).removeClass("jql-display-opts-open")}else{d.minimizeDisplayOptPanel();jQuery(this).removeClass("jql-display-opts-close");jQuery(this).addClass("jql-display-opts-open")}});i.change(function(){d.checkAutoSelectColumns();d.validateMaxIssues()});a.bind("click",function(){var j=AJS.$(this);if(j.prop("checked")){e.prop("checked","checked")}else{e.removeAttr("checked")}d.validate()});e.change(function(){var j=AJS.$("#my-jira-search input:checkbox[name=jira-issue]:not(:checked)").length;if(j>0){a.removeAttr("checked")}else{a.prop("checked","checked")}d.validate()});d.validate(f,h)},changeInsertOptionStatus:function(q,n,f){var r=this;var g=AJS.$("#opt-single");var d=AJS.$("#opt-total");var m=AJS.$("#opt-table");var j=AJS.$("#my-jira-search input:checkbox[name=jira-issue]:checked");var i=AJS.$("#my-jira-search input:checkbox[name=jira-issue-all]").attr("checked")==="checked";var l=j.length===1;var p=j.length>1;var h=j.length===0;var b=AJS.JQLHelper.isSingleKeyJQLExp(AJS.$("#my-jira-search input[name=jiraSearch]").val());var c=function(){if(f&&f.isJqlQuery){m.click()}else{g.click()}};var k=function(){d.attr("disabled","disabled");m.removeAttr("disabled");g.removeAttr("disabled");c();setTimeout(function(){c()},100)};var e=function(){g.attr("disabled","disabled");d.removeAttr("disabled");if(AJS.$("input[name=insert-advanced]:checked").val()==="insert-single"){setTimeout(function(){m.removeAttr("disabled").click()},100)}};var o=function(){m.removeAttr("disabled","disabled");d.removeAttr("disabled","disabled");g.removeAttr("disabled","disabled");var s=AJS.$("input:radio[name=insert-advanced]:checked").val();if(s==="insert-single"){setTimeout(function(){m.click()},100)}};var a=function(){g.attr("disabled","disabled");d.attr("disabled","disabled");m.attr("disabled","disabled");AJS.$(".jql-display-opts-close").click();AJS.$(".jql-display-opts-open").addClass("disabled")};AJS.$(".jql-display-opts-open").removeClass("disabled");g.removeAttr("disabled");d.removeAttr("disabled");m.removeAttr("disabled");if(i&&l&&b){k()}else{if(i&&l&&!b){o()}else{if(p){e()}else{if(l&&!i){k()}else{if(n){e()}else{if(h){a()}}}}}}},isInsertTableType:function(){return AJS.$("input:radio[name=insert-advanced]:checked").val()==="insert-table"},setInsertButtonState:function(){var a=AJS.$(".jql-display-opts-close, .jql-display-opts-open");var b=AJS.$("#jira-maximum-issues");if(!a.length||(a.length&&this.isInsertTableType()&&!this.isValidMaxIssues(b.val()))){this.disableInsert()}else{this.enableInsert()}},analyticPanelActionName:"confluence.jira.plugin.searchadded"});AJS.Editor.JiraConnector.Panels.push(new AJS.Editor.JiraConnector.Panel.Search());
      } catch (err) {
      if (console && console.log && console.error) {
      console.log("Error running batched script.");
      console.error(err);
      }
      } 
      

      Steps to reproduce:

      1. Install a Confluence 5.5.2 instance;
      2. Install a JIRA instance 6.2.6, and add a single line text field with name Length and global context;
        This issue also occurs when defining name Length in the customfield translation.
      3. Setup an application link between Confluence and JIRA;
      4. Create a page and open the JIRA Issues Macro, and try and run any sort of query.

      The results will return, but attempting to click the "Insert" button won't do anything. Checking the JavaScript console in the browser should show the error above.

      Additional information:

      After some debugging we narrowed it down to the fact that Confluence doesn't appear to escape some field names that can be misinterpreted as array method names. In this case, the Jira custom field was called Length and appears to be misinterpreted as a call to the array.length() method of a given array r[]

      This didn't happen with Confluence 5.1.5, so the bug was introduced since then.

      Diagnosis:

      Running this SQL Query on Jira Database should yield the easiest diagnosis if there is a custom field called length:

      Run on Jira Database
      select * from customfield where lower(cfname) = 'length'
      

      Workaround:

      1. Access the URL http://<JIRA_URL>/rest/api/2/field and use the search functionality in your browser to find the word Length, or execute the query bellow to identify the custom field that is causing this issue:
         
        select ps.propertyvalue as "Translation", cf.cfname as "Custom field" from propertystring ps join propertyentry pe on pe.id=ps.id join customfield cf on cf.id=pe.entity_id 
        where pe.property_key like'%jira.translation.custom.fieldcustomfield%' and lower(ps.propertyvalue)='length' or lower(cf.cfname)='length'; 
        
      2. Rename the custom field or custom field translation.

      Attachments

        Issue Links

          Activity

            People

              zxu2@atlassian.com Zac Xu
              b0d88db9bee7 David Corley
              Votes:
              20 Vote for this issue
              Watchers:
              32 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: