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 04:58 AM
Hello Deepika
The security is controlled by ACL which you need access using ACL. I would create an ACL that targets your specific field with the following script:
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('user', gs.getUserID());
//preferably use a system property here
gr.addQuery('group', 'SYS ID OF GROUP');
gr.query();
return gr.hasNext();
Be aware that scripting in ACL is not really a best practice as it will slow down your server.
Kind regards
Quinten
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 05:03 AM
Hi Deepika
1.Check if ACL's are restricting the access to write on that field for members in that group.
2.If members have write access then write OnLoad client script and try using below code.
var usr = g_user.getUserID();
if (usr.isMemberOf('GROUP'))
{
//make readonly false.
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 05:36 AM
Hi rohila,
No there isnt any acls which is restricting users from that group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 05:19 AM
Hi,
you can achieve this using ACL OR Client Script + Display BR as well
Display BR:
g_scratchpad.isMember = gs.getUser().isMemberOf('Group ABC');
client script
function onLoad(){
if(g_scratchpad.isMember.toString() == 'false'){
g_form.setReadOnly('field', true);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader