ACL help for current logged in User

ServiceNow SA
Kilo Guru

I am having issue in ACL.

I want a checkbox field in user table to be edited only by the user who's profile it is. Nobody else has the right to edit that field. For eg. I can make check/uncheck that field in my user profile. Nobody else can do.

I have written a script but that is not working. Can anybody help me on that.

1 ACCEPTED SOLUTION

Hi Sri,



you are comparing user_name with current.sys_id in below line


us.addQuery('user_name', current.sys_id);



This won't work since current.sys_id will give you sys_id and user_name field in user table has user name


use this


gs.getUserName()in place of current_sys_id.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sri,



Can you create a field level write acl for that field with condition as only logged in user can edit that.



Give operation as write,


In the Name drop down select your table, besides that you can select your field.


Then click advance and in script section determine whether user has that profile and set answer = true if you want to make it editable and answer as false if not editable



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Yes i have selected that only,


Here's my script :



var us = new GlideRecord('sys_user');


var userN = '';


us.addQuery('user_name', current.sys_id);


us.query();


if (us.next()){


  userN = us.getValue('sys_id');


}


  if(userN == current.sys_id)


  answer = true;


else


    answer = false;




  But this is not allowing the user to edit even his user profile


Hi Sri,



you are comparing user_name with current.sys_id in below line


us.addQuery('user_name', current.sys_id);



This won't work since current.sys_id will give you sys_id and user_name field in user table has user name


use this


gs.getUserName()in place of current_sys_id.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

@ServiceNow SA 

Hope you are doing good.

Did my reply answer your question?

If so, please mark it correct so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

 

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