Can same field which is shown twice be read only in one tab

Prvn1
Tera Contributor

We are showing same field in two different tabs. Can we make one of them read only ?

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi @Prvn1 

basically, it is not a good idea to have the same field more than one time on the form. This can lead to issues and unexpected behaviors!

And unfortunately you cannot make one field read-only as this was never foreseen by ServiceNow.

Maik

Harish Bainsla
Kilo Patron
Kilo Patron

Hi please try below code

(function () {
// Specify the tab name where you want the field to be read-only
var readOnlyTab = 'TabName';

var fieldName = 'your_field_name';

var currentTab = g_form.getSectionName(fieldName);

if (currentTab == readOnlyTab) {
g_form.setReadOnly(fieldName, true);
}
})();

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Prvn1 

 

Do able but not recommended. And what is the use case of same? 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Harish Bainsla
Kilo Patron
Kilo Patron

If my answer helps please accept solution