I want make multiple fields read only for multiple user groups
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:15 AM
Hi All,
I want make multiple fields read-only for multiple groups on change table, when change state is all except new state.
How can I make fields read only and what is best practice.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:26 AM
Hi @pvv1045330
A similar issue
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:09 AM
HI @pvv1045330 ,
I trust you are doing great.
Please find the below client script for the same :
// Client Script to make fields read-only
(function onLoad() {
// Check if the user is in the required groups
if (isUserInGroups(['change_manager', 'itil'])) {
// Check if the state is not 'New'
var changeState = g_form.getValue('state');
if (changeState !== 'new') {
// Make fields read-only
g_form.setReadOnly('description', true);
g_form.setReadOnly('category', true);
}
}
})();
// Function to check if the user is in any of the specified groups
function isUserInGroups(groups) {
for (var i = 0; i < groups.length; i++) {
if (g_user.hasRole(groups[i])) {
return true;
}
}
return false;
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:20 AM
Hi @pvv1045330 ,
A start recommendation would be to start define:
- When should fields be read-only? Under which circumstances, which groups/users etc.
- When should fields NOT be read-only? Under which circumstances, which groups/users etc.
Based on if you provide specific descriptions and questions to above, it will be much easier to help you.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:35 AM
Hi @AndersBGS ,
- When should fields be read-only? Under which circumstances, which groups/users etc.
a) when change state is assess, authorize, scheduled, implementation, review, closed, canceled.
all fields should be read only except Work notes, Assignment group, Assign to etc.
Group names: service desk, IT support group, etc.
- When should fields NOT be read-only? Under which circumstances, which groups/users etc.
Change state is New all fields should editable form all user.
Thanks,