- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 07:58 AM
Hello all,
i have small requirement that , on custom table list view i have created a new view name called "XXX" , so i need to give list edit permission to the users to edit the fields on list view when they are on view called "XXX",
i have used below script but the script is not working , any suggestion that would be great help.
Note - I have created new role to those users.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 09:39 PM
Please try this script below:
/* Restrict to view = “XXX” */
(function () {
var view = 'default';
// When a browser call is in play, get the ?sysparm_view=value
var req = gs.action.getGlideRequest(); // null if no request
if (req) {
var v = req.getParameter('sysparm_view');
if (v) {
view = v;
}
}
// Only allow if the requested view is “XXX”
answer = (view === 'XXX');
})();
Why switch from gs.getSession().getClientData('sysparm_view')?
gs.action.getGlideRequest() is the supported server‑side way to read URL parameters such as sysparm_view.
- getClientData() relies on UI‑only session data... it isn’t always populated when the script runs in background or via API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:38 PM
🛠️ Problem Name: List Edit Restriction by View
🔍 General Solution Proposal:
To restrict list editing on a custom table view named "XXX", implement a list_edit ACL with a script that checks the current view. This ensures that only users accessing the "XXX" view can edit fields inline, while others are restricted.
📝 Detailed Step-by-Step Solution:
Elevate Roles:
Navigate to your profile and select Elevate Roles.
Check security_admin and submit.
Create a New ACL:
Go to System Security > Access Control (ACL).
Click New to create a new ACL.
Configure ACL Details:
Type: Record
Operation: list_edit
Name: Select your custom table and the specific field to restrict.
Active: Checked
Admin Overrides: Unchecked (if you want to enforce this restriction for admins as well)
Requires Role: Add the role(s) that should have edit permissions in the "XXX" view.
Advanced Script:
Check the Advanced box.
Enter the following script:
(function() { var view = gs.action.getGlideURI().get('sysparm_view'); if (view === 'XXX') { answer = true; } else { answer = false; } })();
This script checks the current view. If it's "XXX", it allows list editing; otherwise, it denies it.
Save the ACL:
Click Submit to save the ACL.
✅ Example Use Case:
Scenario: You have a custom table u_custom_table with a view named "XXX". Only users with the role u_custom_role should be able to edit the u_custom_field inline when accessing the "XXX" view.
Implementation:
Create a list_edit ACL for u_custom_table.u_custom_field.
Assign the role u_custom_role in the ACL.
Use the above script to check for the "XXX" view.
🧪 Testing the Solution:
Impersonate a User:
Impersonate a user with the appropriate role.
Access the "XXX" View:
Navigate to the list view of your custom table.
Ensure you're in the "XXX" view.
Test Inline Editing:
Attempt to edit the field inline.
It should be editable.
Switch Views:
Change to a different view.
Attempt to edit the field inline.
It should be read-only.
📚 Sources:
ServiceNow Community - ACL to restrict users to edit fields from list view:
Discusses creating list_edit ACLs to control inline editing based on roles and views.
ServiceNow Community - Get view name from list control omit new condition script:
Provides insights on retrieving the current view using gs.action.getGlideURI().get('sysparm_view').
If this solution works for you, please mark it as the accepted answer. Let me know if you need further assistance! 😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 09:39 PM
Please try this script below:
/* Restrict to view = “XXX” */
(function () {
var view = 'default';
// When a browser call is in play, get the ?sysparm_view=value
var req = gs.action.getGlideRequest(); // null if no request
if (req) {
var v = req.getParameter('sysparm_view');
if (v) {
view = v;
}
}
// Only allow if the requested view is “XXX”
answer = (view === 'XXX');
})();
Why switch from gs.getSession().getClientData('sysparm_view')?
gs.action.getGlideRequest() is the supported server‑side way to read URL parameters such as sysparm_view.
- getClientData() relies on UI‑only session data... it isn’t always populated when the script runs in background or via API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 11:26 AM
thanks @folusho , it's working as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 06:47 AM
Hi @folusho ,
i found issue that, it allowing to edit the fields in both default and XXX views, how to allow only in XXX view?