i want to create an ACL rule for the field

Kiran Kumar m
Tera Contributor

Hi i have a customer table called CNS customer in that i have a field called FLAG i want to write an ACL for this field 

and in user table we have a customized field called NSA authorised  it's checkbox . 

 

The condition for ACL customer table's FLAG feild is that : if the currently logged in user is not a NSA authorised user then he cant change the field FLAG and when he tries to change that FLAG field a pop-up shOuld come saying that you don't have access to this field 

 

im a fresher so kindly help me with this 

 

THANK YOU 

8 REPLIES 8

manjusha_
Kilo Sage

@Kiran Kumar m 

 

Create a write acl on field FLAG of table CNS customer

In acl script you need to call script include ,in the function pass variable as a currently logged in user as below-

answer=false;

var userId = gs.getUserID();

var userRet = new ScriptIncludeName().checkUserFlag(userId);

answer =userRet;

if answer is true ,then user can edit flag field,if it is false then user won't  be able to edit flag field

Script include function-

 

Create a script include ,create function ,in the script function add below code

function checkUserFlag(userId){

var Nsa_authorized =false;

var currentUser =userId; 

var gr= new GlideRecord('sys_user');

gr.addQuery('sys_id',currentUser);

gr.query();

if(gr.next()){

Nsa_authorized =gr.nsa_flag;

},

return Nsa_authorized;//this returns true or false

}

1.Also for read only field we can not show pop box

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

 

Thanks,

Manjusha Bangale

Hi Manjusha 

 

its not read only field you can perform CRUD operation on that field 

i have a requirment if the currently logged in user is nsa authorized i mean if NSA field in user table  form is checked i mean if its checked true  Then that user if he tries to change the field FLAG then the access to flag should be denied saying you dont have acess to this field 

 

I hope you got my question THANKS

@Fazal Mohammad 

 

I got  your requirement ,when you restrict access to edit a field that means your field becomes read only ,user can not edit the field.

Make below changes in acl script-

answer=false;

var userId = gs.getUserID();

var userRet = new ScriptIncludeName().checkUserFlag(userId);

if(userRet){

answer=false;//this restrict edit access to field Flag for your  logged in user 

}

else {

answer =true;//this allow logged in user to edit Flag field

}

if answer is false ,then user can edit flag field,if it is true then user won't  be able to edit flag field

 

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

Thanks,

Manjusha Bangale

Fazal Mohammad
ServiceNow Employee
ServiceNow Employee

Hi @Kiran Kumar m 

Screenshot 2023-03-21 at 1.43.36 PM.png

 

Screenshot 2023-03-21 at 1.43.22 PM.png

In place of Business rule (sys_script) select the required Table.

And in Filter condition, you can add the condition, In FLAG is CHANGED

 

Please mark this answer, Helpful if it worked for you.

 

Thanks

Fazal