ACL to make fields read-only

Ram150
Tera Expert

Hello,

I have a requirement where I have to make a set of fields in a custom form read-only for two roles, based on another field.

Let me break this down - Let's assume we have a custom form with three fields - Status, Org1 and Org2 . The User isn't filling any information here. Just viewing an existing record.

If the Status is Draft, Org2 should be read-only and if Status is Ready, Org1 and Org2 should be read-only. Again, like I said, the user isn't going to change any field here. So, a Client Script or a UI policy isn't what I want. The fields shouldn't be editable in list view either. Hence I'm think ACLs.

Is there a way to do this? If yes, how? Please let me know.

Any help is appreciated.

Regards,

Ram

1 ACCEPTED SOLUTION

siva_
Giga Guru

Hello Ram , 

 

This can be achieved in two ways 

1 ) Using client scripts 

2) Using ACL 

using client scripts you can initially check whether the logged in user has two roles as you specified above using 

g_user.hasRole("particularRole")||g_user.hasRole("particularRole2"); which returns true if he has that role

and then you can check in the onload client script itself if he has anyof these roles and if g_form.getValue('status')=="Value" then do these g_form.setReadOnly('field_name',true); else the other set of fields to be true 

Ans you can restrict the list editing for the complete table 

 

Using ACL : 

you can check the logged in user role and current forms status value based on that you can make the fields read only using answer = false on field level acl like incident.org1 

the script in acl would be like 

answer = true;

if(gs.hasRole("RoleName")||gs.hasRole("role2"){

if(current.status == "New"){ //change values according to your requirement

answer= false ;

}

like this you have to write two acl's for two fields org1 and org2

 

Hope this helps 

 

Please Mark the response as correct if that really helps

 

Thanks,

Siva

 

View solution in original post

4 REPLIES 4

siva_
Giga Guru

Hello Ram , 

 

This can be achieved in two ways 

1 ) Using client scripts 

2) Using ACL 

using client scripts you can initially check whether the logged in user has two roles as you specified above using 

g_user.hasRole("particularRole")||g_user.hasRole("particularRole2"); which returns true if he has that role

and then you can check in the onload client script itself if he has anyof these roles and if g_form.getValue('status')=="Value" then do these g_form.setReadOnly('field_name',true); else the other set of fields to be true 

Ans you can restrict the list editing for the complete table 

 

Using ACL : 

you can check the logged in user role and current forms status value based on that you can make the fields read only using answer = false on field level acl like incident.org1 

the script in acl would be like 

answer = true;

if(gs.hasRole("RoleName")||gs.hasRole("role2"){

if(current.status == "New"){ //change values according to your requirement

answer= false ;

}

like this you have to write two acl's for two fields org1 and org2

 

Hope this helps 

 

Please Mark the response as correct if that really helps

 

Thanks,

Siva

 

Hello Ram, 

 

Please Mark the response as correct so that it can be removed from unanswered category if that resolved your issue.

 

Thanks,

Siva

Sindhu B1
Giga Expert

 Hi Ram,

You would need to do this with ACL's... I would not recommend it as it can become a maintenance nightmare!

you can simply turn list editing off if it is becoming a problem using "list control".... see screen shots below.
Administering the List Editor - ServiceNow Wiki

 

 

 

 

 

find_real_file.png

 

find_real_file.png

 

 

 

Please mark helpful or correct if it worthy

Thanks and Regards,

Sindhu 

 

shloke04
Kilo Patron

Hey Ram,

 

The Best way to Proceed on this will be via ACL. What you need to do is to have Two "Write" Operation ACL on your required Table one on the Org 1 Field and other on Org 2 Field using the Script below:

 

For the Second ACL on ORG 2 have the script below:

if(current.status =='draft' || current.status == 'ready'){

answer = false;

}

else{

answer = true;

}

 

For the Second ACL on ORG 1 have the script below:

 

if(current.status = 'ready'){

answer=false;

}

else{

answer=true;

}

 

This should work for you.

 

Hope this help. Please mark the answer as helpful/correct based on impact.

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke