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
3 weeks ago
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
3 weeks ago
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
3 weeks 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
3 weeks 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
3 weeks 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SatyanarayanaS,
You can make your field 'read only' on the Dictionary entry record.
System Defintion>Tables open your table and open your field.
Configure the form and add 'Read only' , 'Read only option' fields
check 'Read only' field, then you can select 'Read only option'
options include:
1.Display Read Only: Only human users cannot edit it on the form. Scripts, flows, and APIs can still update it.
2.Client Script Modifiable: Human users and server scripts/APIs cannot edit it, but browser Client Scripts can.
3.Strict Read Only: Completely locked down. Neither human users, Client Scripts, nor server APIs can change it.
