Java script code to make custom field read only not working

Aayush Mohanka May 14, 2020

I have written a js,to make a custom field read only,which is used in editable screen.

Seem below code is not working.

 

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


AJS.$('#showmore').remove();
var editableElms = AJS.$('#field-customfield_10503');
editableElms.css({ "width": "557px", "overflow": "hidden", "display": "inline-block"});
var editButton = AJS.$('#opsbar-edit-issue_container a');
var issueId;
if(editButton){
var href = editButton.attr("href");
if(href){
if(href.indexOf('?id=') > -1){
issueId = href.substring(href.indexOf('?id=')+4);}}
}

var url = ("https://mcb.customerxps.com:2504/efm/fetch.jsp?id=").concat(issueId);// Change ip and port here
AJS.$(" <a id='showmore' target='_blank' href=url >Show more</a>").insertAfter(AJS.$("#field-customfield_10503 p").first());
AJS.$('#showmore').attr("href", url);

AJS.$('#rowForcustomfield_12000').css({"width":"1650px", "height":"300px","overflow":"auto","white-space":"nowrap" });

//AJS.$('#rowForcustomfield_11801').css({"width":"1650px", "height":"300px","overflow":"auto"});

AJS.$('#peoplemodule').hide();
// AJS.$('#datesmodule').hide();
AJS.$('#greenhopper-agile-issue-web-panel').hide();
// AJS.$('#changehistory-tabpanel').hide();
// AJS.$('#activity-stream-issue-tab').hide();


var readOnly = AJS.$('#customfield_12600');
readOnly.attr("readonly", true);
});

 

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 15, 2020

That code will work in a couple of older versions of Jira, but only in a couple of places.

In more recent versions of Jira, you're going to need to write a lot more js code, and bear in mind you will need to write different code for every place where the field might be editable.  And think about how you might control REST calls to edit it (as your js can't run for those)

Suggest an answer

Log in or Sign up to answer