Making Field Read Only across all the sections of the Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have written a client script to make the field read only on certain conditions, it is making the field read only on the main form but I have the same field added to another section of the form, there it is editable, How to enforce the field as read only across all sections of the form?
Can anyone help me on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
what do you mean by main form?
If that field is added at multiple places on form then making that read-only will make it readonly at all places
didn't get your question
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
The Main Incident Section and the same field in the Notes Section.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi,
Why not use UI policy/data policy rather than client script and see if it changes anything. ServiceNow recommends using UI policies rather than client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @SatyanarayanaS ,
I have tried your usecase , for my practice table username field . So i have tried this dom manipulation in order to make username field readonly . Ensure that isolated script is unchecked .
function onLoad() {
g_form.setReadOnly('u_username',true);
var sections = g_form.getSections();
// 0 is the first section
var targetSection = sections[1];
if (targetSection) {
var field = targetSection.querySelector('[id*="sys_display.u_practice.u_username"]');
alert(field)
if (field) {
field.disabled = true;
field.readOnly = true;
}
}
}
If this helps you then mark it as helpful and accept as solution .
Regards,
Aditya