- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 10:44 PM
I want to make all fields read-only when a condition is met.
I was planning to handle this with a script instead of creating UI policy actions one by one.
Identify the dictionary records present in the table in the display business rule and store the field name list in "g_scratchpad.all_field"
var tmp_rec = new GlideRecord("sys_dictionary");
tmp_rec.addQuery("name", current.getTableName());
tmp_rec.addQuery("internal_type", "!=", "collection");
tmp_rec.addQuery("element", "!=", "sys_id");
tmp_rec.query();
var filed_name_list = [];
while (tmp_rec.next())
filed_name_list.push(tmp_rec.getValue("element"));
g_scratchpad.all_field = filed_name_list;
Use the script below in the UI policy to perform read-only processing on the field names in the list.
for (var i = 0; i <= g_scratchpad.all_field.length; i++) {
g_form.setReadOnly(g_scratchpad.all_field[i], true);
}
For some reason, some fields were not made read-only. . .
Is there a setting to make it read-only in bulk other than this method?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 10:54 PM
if a field is set as Mandatory, you cannot set it to readOnly. Are those fields mandatory?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 11:50 PM
Hello @bonsai ,
You can achieve this using client script. Find the below code
var fields = g_form.getEditableFields();
for(var i=0; i<fields.length; i++){
g_form.setReadOnly(fields[i],true);
}
Please mark my answer correct & helpful, if it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 10:54 PM
if a field is set as Mandatory, you cannot set it to readOnly. Are those fields mandatory?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 11:28 PM
There is an issue where two types of fields, required and non-required, are not set to read-only.
Required fields are not blank.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 11:31 PM
can you share the screenshot of those fields which are not set to readonly?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 11:41 PM
I'm sorry, but I cannot share the capture as it includes business details.