ACL script. How to access field information

runnah
Kilo Contributor

Hi,

I am creating an ACL script to prevent users with a custom role from viewing more than the records that they have created. I need to check the field in my table, user, to see if it is equal to the current logged in user. The user value is stored in my table as their display name rather than sys id, so I am using gs.getUserDisplayName(); to compare their values. I have seen examples of people using current.field_name to access information from a record, but I am still unsuccessful. Attached below is what I am currently working with. Please comment if you have any recommendations. Thank you!

acl.PNG

1 ACCEPTED SOLUTION

Hey Runna,



Change the drop down value in name field to "None" and it should work. Please refer below screenshot and let me know if you are blocked.


Screen Shot 2016-08-04 at 12.04.18 PM.png


View solution in original post

9 REPLIES 9

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Runna,



Could you should the condition you're currently using. You should be able to do something like this in the condition builder or script box though:



e8076853a5.png


Hi Brad,



Thank you for your response! My condition is not accepting a value of javascript:gs.getUserDisplayName(); most likely because it is a reference field. It immediately evaluates when I type it in. I am using Fugi release.  


currentuseracl.PNG


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Runna,



If the reference field is a user reference, then you don't need any scripting, just do this:



4c5b9f1446.png


Kalaiarasan Pus
Giga Sage

From your question it seems that you should be using gs.hasRole instead of the function to get displayname.