- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:35 PM
How can you allow a user to update the incident state but restrict them from closing it in the list view?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:48 PM
Solution
You can create an OnCellEdit Client Script on state field that checks if the new state value is "Closed." If the user tries to close the incident by changing the state to "Closed," the script will block the update. If the new state is anything other than "Closed," the record update will proceed as normal.
function onCellEdit(tableName, record, columnName, oldValue, newValue, callback) {
if (newValue === 'Closed') {
// Prevent update if the state is being set to "Closed"
callback(false); // Pass 'false' to prevent update
} else {
// Allow update if the state is not being set to "Closed"
callback(true); // Pass 'true' to allow update
}
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:58 PM
Hi @SandeepKSingh ,
write an on cell edit client script with the below code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:54 PM
you can achieve this by using a UI Policy or Business Rule
UI Policy/Client Script :
in the list view, create a UI Policy/Client Script to disable the "State" field when the value is set to "Closed."
Business Rule:
write a Before Update Business Rule on the incident table to restrict users from setting the "State" to "Closed" unless they have specific roles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:58 PM
Hi @SandeepKSingh ,
write an on cell edit client script with the below code :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 10:02 PM
Thanks @Ravi Gaurav and @SriharshaYe it worked 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 10:10 PM
onCellEdit client script use on the List view when we edit or change the field value using (g_list)
if (control == 'state' && newValue == '7') {
g_form.addErrorMessage("You are not allowed to close incidents from the list view.");
g_form.setValue('state', oldValue);
}
This approach only prevents users from closing incidents in the list view. If you also want to restrict closure in the form view, consider combining this with a UI Policy or Business Rule.