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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
If the same field is added in multiple locations on a form and is made read-only using a UI Policy or Client Script, the read-only behavior will be applied to that field in all places where it appears, provided the specified condition is met.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
47m ago
Hi @SatyanarayanaS ,
This is an expected behaviour when the same field is added to a form more than once. Having duplicate instances of the same field can lead to inconsistent behaviour with Client Scripts and UI Policies, as the behaviour may not be applied consistently across all instances.
Please refer to the below article:
Duplicate fields on a form can lead to unexpected results with UI policies
If you find this information useful, please mark the response as helpful and accept it as the solution.
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9m ago
Hello @SatyanarayanaS ,
Use a UI Policy
1.Navigate to All > System UI > UI Policies and click New.
2.Set the table name and define your conditions (e.g., matching the same conditions from your script).
3.Save the record.
4.Scroll down to the UI Policy Actions related list and click New.
5.Select your field (u_link) and set Read only to True.
OR
Update Your Client Script using DOM Querying
If you must stick to using your current asynchronous GlideAjax client script structure, you can bypass standard g_form limitations by using standard JavaScript to query all elements representing that field on the form.
Replace your g_form.setReadOnly('u_link', true); line with a query selector loop:
// Target all element inputs/controls for the 'u_link' field across all sections
var fieldElements = document.querySelectorAll('[id*="u_link"]');
fieldElements.forEach(function(element) {
element.disabled = true; // Disables input fields
element.readOnly = true; // Sets fields to read-only
});
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You,
Sujit Jadhav