An ACL script is server-side code attached to an access control rule. It participates in the rule’s permission checks and can set answer to true or false. Use it for logic that roles and conditions cannot express, such as comparing the record with the signed-in user.
What an ACL script does in the access check
An access control rule (ACL) guards one object and one operation. The object can be a table, a field on a table, or another resource such as a REST endpoint. The operation is something like read, write, create or delete.
A rule can combine required roles, security attributes, data conditions, and a script. The configured checks must pass for that rule to succeed. A user needs one of the roles listed in Requires role, rather than all listed roles.
Use Requires role to identify eligible users, Data Condition to check record values, and Script for comparisons that need code. Keeping those responsibilities separate makes a failed check easier to locate.
A useful habit is to write the requirement as a plain sentence first. If the sentence only mentions roles, you do not need a script. If it mentions the record’s own values, a condition may be enough. A script earns its place when it compares values to the signed-in user, or to another record.
Where the script runs and what it can see
Record-dependent scripts run when the access check has record context. Pre-query field checks examine roles without evaluating scripts that depend on record contents; post-query checks can evaluate roles, conditions, and scripts. A few objects are available to scripted checks:
- current normally represents the record being checked, as a GlideRecord. You can read its fields, for example current.assigned_to or current.state.
- gs is the GlideSystem object. Use gs.getUserID() for the sys_id of the signed-in user and gs.hasRole(‘role_name’) for a role test.
- answer is the result. Set it to true to pass the scripted check and false to fail it.
A basic example for a read rule on a table that has both assigned_to and caller_id fields, such as incident, letting a user see a record when they are the assignee or the caller:
answer = (current.assigned_to == gs.getUserID()) ||
(current.caller_id == gs.getUserID());
This expression tests the assignee and caller relationship. It does not establish the final access result by itself: matching table and field rules still matter. If the logic grows to dozens of lines, review whether simpler roles and data conditions can express part of it.
Set answer explicitly. It makes the decision point clear to anyone opening the rule later, and it gives you one line to inspect when a result surprises you.
Writing an ACL script step by step
To create or update an ACL, an administrator must elevate privileges to security_admin. An admin user can view and debug ACLs without that elevation. Check the available fields on your instance and release before applying these steps.
- Decide the object and operation. Pick the table, or the table and field, and one operation. A rule for read does not cover write. If users should read and edit, you need both rules.
- Start without a script. Set roles and a condition first. Test. Add a script if a real requirement is left over.
- Create the rule. Navigate to System Security > Access Control (ACL), select New, and choose Type, Operation, Decision Type, and Name. Fill in Requires role and Data Condition as needed. Select Active to enforce the rule.
- Add the script. Select Advanced to display the advanced fields, then enter the logic in Script. Generate a boolean result or assign the answer variable. Save from the form header. Hiding Script on the form does not disable a script already stored there.
- Test as real users. Impersonate a user who should get in and one who should not, and try the record, a list view and, if relevant, an API call.
- Record what you saw. Note which user, which operation and which result. A short table of expected and actual outcomes is enough, and it becomes your regression check the next time someone changes the rule.
Write down, in the rule’s description, what the rule is meant to allow and why. The description gives an auditor context for the rule.
Mistakes that cause trouble
Leaving the result unclear or using the wrong value type. The script must produce a true or false response. When using answer, assign it on each path through the script; an ACL can also use an expression that evaluates to a boolean. Prefer an explicit result that a reviewer can follow. Assign a real comparison, not a bare field value. For example, writing answer = current.assigned_to; gives a field value rather than a true or false result. Write a comparison instead, such as answer = (current.assigned_to == gs.getUserID()); so the result is unambiguous.
Heavy queries in the script. Record-level checks can be evaluated across a list of returned rows. Treat additional lookups as a performance review point: identify the exact relationship needed, constrain the lookup, and compare list response times before and after the change.
Relying on the client. An ACL is what the platform checks when a session requests data. Hiding a field with a client script or a UI policy changes what the form shows, but it does not protect the data. Use the ACL for security and the form tools for presentation.
Testing only as an administrator. Administrators can pass role checks that ordinary users fail, so a rule that looks fine in your own session may block the people it is meant to serve. Impersonate a user with the narrowest role that should have access, and then one without it.
A second pattern: write access by state
Suppose users may edit an open record when assigned to it. Put the allowed states in Data Condition using the target table’s choices, then use the assignment comparison in Script:
answer = (current.assigned_to == gs.getUserID());
This separates the lifecycle requirement from the user relationship. Test an assigned open record, an unassigned open record, and an assigned record outside the allowed states. A matching assignment should not compensate for a failed data condition.
State values are stored as the table’s choice values, which are often numbers on task-based tables, so compare against the value your table actually stores rather than the label shown on screen. Comparing against the label text is one reason a state-based rule can appear to do nothing.
Trace the complete access decision
A false result on one Allow-If ACL does not establish a universal denial. Another matching Allow-If rule at the same processing point can pass. Conversely, a true script does not bypass a failed table check or field check. Identify the operation and object first, then examine the matching rules before changing the expression.
Decision Type also matters: Deny Unless blocks access unless its requirements succeed, while Allow If grants access when its requirements succeed within the applicable checks. Review that choice before treating a script as an exception to another rule.
Check Admin overrides when an administrator gets a different result. If selected, admin users pass that ACL regardless of its script and role restrictions, subject to the nobody role exception. Clearing the option requires administrators to satisfy the data condition or script, but they still pass role checks.
Keep expected results for a permitted user and a denied user, including record identity and operation. Test field visibility separately from editability. For the wider control model, see instance security and access control.
For help planning this work, see ServiceNow implementation.
Planning, ownership and review
ACL scripts are small, but they protect data, so treat them like any other piece of security and access design.
- Name an owner. Every script rule should have a person or team who answers for it. Without one, a rule that is no longer needed can stay in place for years.
- Review with a second pair of eyes. Ask someone who did not write the script to read it and say what it allows, in their own words. If their summary differs from yours, the script or its description needs work.
Questions about ACL script edge cases
Can a scoped ACL script evaluate a table in another scope?
Scripted conditions are restricted when the table is in a different scope from the ACL. Confirm the application selected in the application picker before editing. A cross-scope field being available does not mean a scripted table check is permitted.
Why can current refer to an unexpected record?
For an evaluated item in a related list, current can refer to the record that contains the related list. Check that context before reusing a comparison written for a standalone form; otherwise, the script may inspect fields on a different record.
Can a create ACL depend on a value entered in a new form?
Fields on a new record are considered empty until it is saved. A create condition that expects an existing value can fail. Test the initial creation request separately from updates to a saved record before choosing the condition.
Does a blank ACL provide unrestricted access?
Empty or invalid ACLs are denied by default. Do not remove all requirements to troubleshoot an access problem. Inspect the configured components and use a controlled test case instead of turning the ACL into an empty rule.