Can you make a field read-only in one section of a form but not everywhere?

Nick Peters
Tera Guru

By using tabs, you can add the same field on each tab in addition to it also being on the main form. Is there a way to set the field to read-only on one of the tabs, but allow it to still be writable on the main form? I'm thinking not, but if anyone can either confirm my suspicions or inform me of a way that this is possible, it would be greatly appreciated.

Thank you.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Nick,



You cannot set the same field to be read only in one tab and editable on the main form.


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Nick,



You cannot set the same field to be read only in one tab and editable on the main form.


Bharath40
Giga Guru

Hi Nick.



You are correct it is not possible to have read only on tabs other than main form. It will apply to both.


sndangibbard
Mega Guru

Technically this is possible with an onLoad client script on the form, though it requires some DOM manipulation which ServiceNow generally does not recommend. For example, Short Description field in the main section and then also in two different tabbed sections, this script would make the field read only in the first tabbed section



//get form sections


var sections = g_form.getSections();




//get the first tabbed section (section[0] is the 'main' section, section[1] is the first tabbed section etc)


var $section1 = jQuery(sections[1]);




//find the correct element using system name of column: input[id$="COLUMN_NAME"].form-control


var $el = $section1.find('input[id$="short_description"].form-control');




//mark as read only


$el.attr('readonly', 'readonly');



Just to reiterate, possible but not recommended.