- 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
Friday
I would highlight a potential issue here:
If you would like to make the fields read-only on the form, using client script(s), it can be done (see the previous comment), but you have to handle the Save/Update buttons (UI actions) as well.
Client-side scripts do not prevent server-side updates. A field can easily be made editable directly in the browser(DOM manipulation).
So I would consider using server-side restriction as well. (For example defining an ACL)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
OOB Servicenow Make Closed incident fields read only using the Write ACL for Itil user.
Link : https://<your_instance_name >.service-now.com/sys_security_acl.do?sys_id=66ec26370a0a0b0100a67b597d415b84&sysparm_view=&sysparm_domain=null&sysparm_domain_scope=null&sysparm_record_row=1&sysparm_record_rows=2&sysparm_record_list=operation%3dwrite%5ename%3dincident%5eORDERBY
Instead of creating Client Script, I will suggest to create other Write ACL with your required ACL role or just update ACL role in the existing ACL.