- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 09:45 PM
Hello,
I was trying to set Assignment group and Assigned to fields as read-only depending on the role using a client script (this is for a specific task and has to be a client script), but I have found that I can't make it work with any of the fields using
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:06 PM
Hi @SebCastro , a UI Policy is overriding your Client Script.
search for a UI policy - 'Make fields read-only on close'. If you disable it and run your client script, it will work. But since it is OOB and it is not recommended to disable it.
I recommend using a UI policy to make fields/columns read-only instead of client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:24 PM
if you want fields to be readonly for incident_manager then use this
function onLoad() {
// Check if user has the required role
if (g_user.hasRole('incident_manager')) {
g_form.setReadOnly('assignment_group', true);
g_form.setReadOnly('assigned_to', true);
}
}
If you want fields to be readonly if logged in user doesn't have incident_manager role then use this
function onLoad() {
// Check if user has the required role
if (!g_user.hasRole('incident_manager')) {
g_form.setReadOnly('assignment_group', true);
g_form.setReadOnly('assigned_to', true);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:37 PM
Hi @SebCastro
UI Policy get applied when there is a conflicting logic with Client scripts.
I recommenced you to use UI policy instead of client script.
It will work.
Regards,
Sourabh