- 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 09:53 PM
Hi @SebCastro ,
(function executeRule(current, previous /*null when async*/) {
// Check if the user has a specific role (replace 'your_role' with the actual role)
// add your conditions needed
if (g_user.hasRole('your_role')) {
// Make 'Assignment Group' and 'Assigned To' read-only
g_form.setReadOnly('assignment_group', true);
g_form.setReadOnly('assigned_to', true);
}
else {
// Optionally, you can make them editable if the role condition is not met
g_form.setReadOnly('assignment_group', false);
g_form.setReadOnly('assigned_to', false);
}
})(current, previous);
please mark it as helpful, solution is fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:04 PM
Please try below code:
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);
}
}
Please mark helpful/correct, if this helps you
- 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-19-2025 03:52 AM
Thanks a lot for reading my question carefully and answering what I was asking for, I could confirm the UI policy you mentioned was the one causing me issues, and for the sake of the task in hand (it's a practice task so I NEED to do it via Client script). Appreciate it.