- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Dear Community Members
I wanted to make all editable fields readonly, after incident state is closed.
Can someone provide me clientscript for this requirement.
Please help, thanks for your support
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday - last edited Thursday
Hi @aravind1patil1 ,
You can achieve this using an onLoad Client Script on the Incident table.
function onLoad() {
// Replace '7' with the actual choice value for your 'Closed' state if it differs
var state = g_form.getValue('state');
if (state == '7') {
var fields = g_form.getEditableFields();
for (var i = 0; i < fields.length; i++) {
// Keep the state field itself editable or make everything read-only based on your preference
g_form.setReadOnly(fields[i], true);
}
}
}
Hope this helps! and resolves your issue, please mark the response as helpful and accept it as the solution.
Regards,
Sandesh Powar
ServiceNow Rising Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hello @aravind1patil1
Out of the box, closed incidents are usually already read only for itil users. This comes from a UI policy named Make fields read-only on close (table: sys_ui_policy) that checks the state.
Please check whether it is inactive or modified on your instance, because that may be the real reason the form is editable.
If you still need a client script, create an onLoad client script on the Incident table with the code below.
function onLoad() {
// 7 is the default value of Closed, please check it on your instance
if (g_form.getValue('state') == '7') {
var fields = g_form.getEditableFields();
for (var i = 0; i < fields.length; i++) {
g_form.setReadOnly(fields[i], true);
}
}
}
Hope this helps!
Thank You!
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi,
Always try to figure things out on your own first, as it’s a great way to build your skills. If you get stuck at any point, you can ask for help anytime. 🙂
Here is the code:
function onLoad() {
// Check if Incident state is Closed
if (g_form.getValue('state') == '7') {
// Get all fields on the form
var fields = g_form.getEditableFields();
// Make all editable fields read-only
for (var i = 0; i < fields.length; i++) {
g_form.setReadOnly(fields[i], true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hello @aravind1patil1 ,
You can use onload client script :
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('state')=='7')
{
var data=g_form.getEditableFields();
for( var i=0; i < data.length;i++)
{
g_form.setReadOnly(data[i],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
Thursday - last edited Thursday
Hi @aravind1patil1 ,
You can achieve this using an onLoad Client Script on the Incident table.
function onLoad() {
// Replace '7' with the actual choice value for your 'Closed' state if it differs
var state = g_form.getValue('state');
if (state == '7') {
var fields = g_form.getEditableFields();
for (var i = 0; i < fields.length; i++) {
// Keep the state field itself editable or make everything read-only based on your preference
g_form.setReadOnly(fields[i], true);
}
}
}
Hope this helps! and resolves your issue, please mark the response as helpful and accept it as the solution.
Regards,
Sandesh Powar
ServiceNow Rising Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hello @aravind1patil1
Out of the box, closed incidents are usually already read only for itil users. This comes from a UI policy named Make fields read-only on close (table: sys_ui_policy) that checks the state.
Please check whether it is inactive or modified on your instance, because that may be the real reason the form is editable.
If you still need a client script, create an onLoad client script on the Incident table with the code below.
function onLoad() {
// 7 is the default value of Closed, please check it on your instance
if (g_form.getValue('state') == '7') {
var fields = g_form.getEditableFields();
for (var i = 0; i < fields.length; i++) {
g_form.setReadOnly(fields[i], true);
}
}
}
Hope this helps!
Thank You!
Juhi Poddar