The CreatorCon Call for Content is officially open! Get started here.

How to make a readonly field as editable for users in particular group

test1231998
Tera Contributor

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

17 REPLIES 17

quintenvandenb1
Giga Expert

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

Voona Rohila
Mega Patron
Mega Patron

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

Hi rohila,

 

No there isnt any acls which is restricting users from that group.

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader