Make field editable to only sys admins

Harish74
Tera Expert

Hi,

I have created a custom field on sys_user_group table. I want only sysadmins should be able to edit that field. 

I know that we can do it with ACL. But I'm not sure if this can be done with UI policy or client scripts. 

Suggest me which is the best suitable method to achieve this?

If this can be done with UI policy or client scripts please provide me required script.

3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

Hello,

Yes you can also achieve this using Onload client script:-

Please use the below script:-

function onLoad() {
   //Type appropriate comment here, and begin script below
  if( g_user.hasRole('admin'))
	  {
		  g_form.setReadOnly('fieldname',false);
	  }
	else
		{
			g_form.setReadOnly('fieldname',true);
		}
}

Please mark answer correct/helpful based on Impact

 

Anil Lande
Kilo Patron

Hi,

Yes you can use Ui Policy and Client script to make field read-only/editable based on logged IN user role:

Please check below links for similar solutions:

you can use g_user.hasRole('admin');

 

But using ACL would be best solution

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I would recommend using ACL at field level WRITE

onLoad client script

function onLoad() {
	//Type appropriate comment here, and begin script below
	if(!g_user.hasRoleExactly('admin'))
	{
		g_form.setReadOnly('fieldname',true);
	}
}

Regards
Ankur

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