- 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: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:55 PM
Let me have a Try and I will get Back to you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:48 PM
Use this Script:
(function executeRule(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === oldValue) return; // Skip if loading or no change
if (control === 'state') { // Check if editing "state"
if (newValue == '7') { // Restrict "Closed" state
g_form.addErrorMessage('Cannot set state to Closed.');
g_form.setValue('state', oldValue); // Revert value
return false;
}
}
})(control, oldValue, newValue, isLoading, isTemplate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 09:54 PM
I guess you have just copy pasted from chatGPT.. I asked for onCellEdit and you are giving onChange.. I am sorry buddy your code is of no Help.