onCellEdit client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 02:24 PM
Hi folks,
If admin user is logged in only he can edit the list not other user how can I solve this problem use of onCellEdit client script?
Thanks,
Mustafeez.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 05:28 PM - edited 03-21-2024 05:29 PM
Hi @Mustafeez,
Are you saying only the Admin should be able to modify the records in the list view?
If so, do you have to use the onCellEdit client script?
There are multiple ways to do this:
- Use List Control - https://www.servicenow.com/community/developer-forum/how-do-you-disable-list-editing-for-a-particula...
- Use ACL - https://www.servicenow.com/community/developer-forum/how-do-you-disable-list-editing-for-a-particula...
- Disable it completely via system property - https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/list-adminis...
I believe the 1st and last options will apply even to the admins. So ACL might be the best way for you.
Cheers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:51 PM
Hi @Mustafeez
OnCellEdit client script can be used for only one single field to restrict in list layout.
if you want to lock all field then list_edit acl will do,
create a read acl on tablename.* like below
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 07:34 PM
Hi @Mustafeez On cell edit is applicable only for particular field if you wants to apply all the fields use ACL or List Control
You can disable list editing using List Controls. To do this:
1. Right-click on a column in the list view. Select Configure > List Control.
2. In the List Control, change the List edit type to Disable list editing.
I Hope this helps and mark Helpful!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 08:38 PM
Client script:
function onCellEdit(fieldName, oldValue, newValue, field, rowSysId, displayValue) {
// Check if the logged-in user is an admin
if (!g_user.hasRole('admin')) {
// If not admin, prevent the edit
alert("You do not have permission to edit this list.");
return false; // Prevent edit
}
// Allow edit if the user is an admin
return true;
}
Additionally, perform a server-side check to enforce security. Even if the client script is bypassed, this server-side check will prevent unauthorized edits. you can create ACL or before update business rule
BR:
if (!gs.hasRole('admin')) {
// If not admin, prevent the update
gs.addErrorMessage("You do not have permission to edit this list.");
current.setAbortAction(true); // Cancel the update
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks