How to make field ready-only based on the role?

siva58
Tera Contributor

I created a form and I want to make one  field read-only for the certain roles.

.how to achive this.

ex: i need manager  field non-editable for the user who have the these two roles 1. employee manager, 2. project manager.

 

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello,

Please try this in on load client script

if(g_user.hasRoleExactly('your role name'))

{

g_form.setReadOnly('your field name',true);

}

please mark my response correct if it helped you

View solution in original post

4 REPLIES 4

Chandu Telu
Tera Guru
Tera Guru

Hi Siva,

It can achieved in multiple ways

1. ACL is Best practice check the role make read-only

https://community.servicenow.com/community?id=community_question&sys_id=afe88471dbaf7304feb1a851ca961967

https://community.servicenow.com/community?id=community_question&sys_id=a4302ffcdb43db449d612926ca96192e

 

Thanks
Chandu Telu
Please Mark Correct/helpful, if applicable,

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

ACL is the recommended approach i.e. field level WRITE ACL on that field of the table

Another way

1) onLoad client script

Regards
Ankur

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

i have written onload client script .but it was not working

Mohith Devatte
Tera Sage
Tera Sage

Hello,

Please try this in on load client script

if(g_user.hasRoleExactly('your role name'))

{

g_form.setReadOnly('your field name',true);

}

please mark my response correct if it helped you