How to make field ready-only by role?

Randy33
Tera Guru

I created a form and I want to make all field read-only for those with a certain role.  I'm new to this and was wondering the best approach.

Thanks.

1 ACCEPTED SOLUTION

Dinesh Nikam
Mega Guru

Hello Randy@RL,

 Best practice for your requirement is that Use ACL ,

In Write ACL you have to give role only to which you want to give access to a user who having particular role .

For Example  If a user with ITIL role can edit all fields in the table other than that cant edit.

so i will go to ACL table and select table on which i want give permissions to edit.

select 'Write' ACL  in that Click on the advanced write code .

 

Code in Advanced section of ACL

 

if(gs.hasRole('certain role you want add'))
    
{
    
    answer = false;
    
}

else {
    
    answer = true;
    
}

find_real_file.png

 

find_real_file.png

find_real_file.png

 

find_real_file.png

 

Test User doesnt have ITIL role So all fields are read only for him.

 

 

Thank you.

 

PLEASE mark my ANSWER as CORRECT if it served your purpose.

 

View solution in original post

3 REPLIES 3

Mike Patel
Tera Sage

you can create onLoad client script that check logged in user role 

function onLoad() {
if (g_user.hasRole('xyz')){
g_form.setReadOnly('your field', true);
}}

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Randy,

 

If field security needs to change as a form is being filled out, use UI policies and client scripts, which are evaluated and run on the client, that is, the browser. For example, when a support engineer changes the incident state to resolved or closed, one or more fields change from editable to read-only to prevent additional changes.

Note: Client-side security with UI policies and client scripts is not as secure as server-side security. Most modern browsers allow users to change attributes of the data sent to the client, including read-only or hidden fields.


If the data is not dynamically changing on the form, that is, the read-only or edit attribute does not change after the form is loaded, ACLs are recommended. ACLs are evaluated and enforced entirely on the server, making them much more secure than UI policies and client scripts.

 

Thanks,

Pradeep Sharma

 

 

Dinesh Nikam
Mega Guru

Hello Randy@RL,

 Best practice for your requirement is that Use ACL ,

In Write ACL you have to give role only to which you want to give access to a user who having particular role .

For Example  If a user with ITIL role can edit all fields in the table other than that cant edit.

so i will go to ACL table and select table on which i want give permissions to edit.

select 'Write' ACL  in that Click on the advanced write code .

 

Code in Advanced section of ACL

 

if(gs.hasRole('certain role you want add'))
    
{
    
    answer = false;
    
}

else {
    
    answer = true;
    
}

find_real_file.png

 

find_real_file.png

find_real_file.png

 

find_real_file.png

 

Test User doesnt have ITIL role So all fields are read only for him.

 

 

Thank you.

 

PLEASE mark my ANSWER as CORRECT if it served your purpose.