How to make a readonly field as editable for users in particular group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 04:53 AM
I have a field company on cmdb_ci table which is read only for all users except admin. I want to make this field editable for only those users belonging to a particular group. can anyone please help me with the code or solution
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 06:58 AM
Yes this is what I want But I dont see it working as expected
function onLoad(){
if(g_scratchpad.isMember.toString() == 'true'){
g_form.setReadOnly('company', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 08:14 AM
Hi,
As per your question you require this
1) if the logged in user is member of that group then it is editable
2) if the logged in user is not member of that group then it is read-only
so my script does the same
you should use false to compare
function onLoad(){
if(g_scratchpad.isMember.toString() == 'false'){
// also if that field is mandatory first make it non-mandatory
g_form.setMandatory('company', false);
g_form.setReadOnly('company', true);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 03:17 AM
Hope you are doing good.
Would you mind marking the best matching answer as correct and helpful, to close this thread?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader