- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 07:08 AM
Hi Team,
I Need to make all the fields an interaction form read only when the state is closed for SOW view.
am trying to do in UI policy, instead of adding all the 12 fields in UI Policy action, i need a script to write in the run script and to achieve.
regards,
Abhilasha G T
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 08:11 AM
create a table.None WRITE ACL and add condition as State [IS NOT] Closed -> Easiest approach
OR
try this and create onload client script and uncheck Global checkbox and add the correct view name so that this script runs only for that view
function onLoad() {
if (g_form.getValue('state') == 'closed') {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 08:11 AM
create a table.None WRITE ACL and add condition as State [IS NOT] Closed -> Easiest approach
OR
try this and create onload client script and uncheck Global checkbox and add the correct view name so that this script runs only for that view
function onLoad() {
if (g_form.getValue('state') == 'closed') {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 08:21 AM
In the client side script you can use below code.
Also you can do this with ACL as well as that's the most preferred way of doing it.
var fieldname = g_form.getEditableFields();
for (var x = 0; x < fieldname.length; x++) {
g_form.setReadOnly(fieldname[x], true);
}