how to make read only fields to certain role users using UI policy ?

String
Kilo Sage

Hi Team ,

Am trying to make read only fields in incident for agent role users ,But I can't  find  any option for roles in UI policy 

 

Please guide me 

2 ACCEPTED SOLUTIONS

Prince Arora
Tera Sage
Tera Sage

@String 

 

This scenario is best handled with the help of ACLs instead of UI policy, but still if you want to make read only with script you can create a new client script "on load" on the incident table and try below mentioned script(Not tested):

 

 

if(g_user.hasRole("ROLE") ) {
	 var fields = g_form.getEditableFields();
         for (var x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], true);
         }
	}

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

@String 

 

I have seen you marked my answer helpful!

Please Accept the solution if it has answered your query, it would be helpful for future readers too

View solution in original post

5 REPLIES 5

Upsilon
Giga Guru

Hi, 

You cannot do it by UI Policy but you can do it by onLoad client script 

 

if(gs.hasRole('role1,role2')) {// set readonly your field}
else  {// set editable your field}

 

but isn't it better to do this kind of things by acl. It's more suitable and ensure that users cannot edit the field in the lists

Regards

Prince Arora
Tera Sage
Tera Sage

@String 

 

This scenario is best handled with the help of ACLs instead of UI policy, but still if you want to make read only with script you can create a new client script "on load" on the incident table and try below mentioned script(Not tested):

 

 

if(g_user.hasRole("ROLE") ) {
	 var fields = g_form.getEditableFields();
         for (var x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], true);
         }
	}

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

@String 

 

I have seen you marked my answer helpful!

Please Accept the solution if it has answered your query, it would be helpful for future readers too

Mehta
Kilo Sage
Kilo Sage

As per best practice it should be through ACls, but if want to achieve it you can use Onload Client Script and use the below sample code : 

if(g_user.hasRoleExactly('itil'))
{
g_form.setReadOnly('fieldName1', true);
g_form.setReadOnly('fieldName2', true);
g_form.setReadOnly('fieldName3', true);
}