Restrict which records a user can see
Limit some users to a subset of a table's records with a table record restriction, for example requesters to their own incidents.
Use a table record restriction when users can read a table but should see only some of its records. A script decides which users are restricted and which records they keep.
Before you begin
- You need the
administratorrole. - Switch to the Administration workspace with the Workspace selector at the foot of the menu.
- A permission must let the users read the table. See Permissions.
- Decide the test the script makes: which users it restricts, by role or group, and which records they keep. A restriction has no role field.
Steps
-
Go to Access & security → Roles & permissions → Table record restrictions.

The Table record restrictions item in the Access & security menu. -
Select New.

The empty Create Table record restriction form, with Name, Description, Table, the Config tab and Query. -
Fill in the fields above Query. All three are required.
Field What to enter Example Name A name that says what is restricted. Incident - Record visibility restrictions Description What the restriction does and for whom. The restrictions for incident records for non agent users. Table The table to restrict. Incident -
Write the Query script. Set
answerto the query to add for the users you restrict, and leave it unset for everyone else. This script is the default Incident restriction. Users withoutitsm_agentkeep only the incidents where they are the Requestor or the Requested for.if (!user.hasRole("itsm_agent")) { answer = OR( EQUAL("Requestor", user.getID()), EQUAL("RequestedFor", user.getID()) ); }
The default Incident restriction, with Name, Description, Table, the Config tab and its Query script. -
On the Config tab, set Active to Yes. A new restriction is not active.
-
Select Create.
-
Impersonate a user the script restricts and open the table to confirm what they see. See Impersonate a user.
Result
Servicely runs the script whenever anyone queries the table, and adds the query in answer to the user’s own. Users the script restricts see only the matching records, including when they open a record from a link. Other users see the table as before. A restriction narrows what permissions and tenancy allow, and never widens it.
Options
| To | Do this |
|---|---|
| Restrict by a role the users hold | Test for the role in the script, and give the role to the users who should be restricted. |
| Restrict everyone who lacks a role, as the default Incident restriction does | Test for the missing role in the script, and give the role to the users who should not be restricted. |
| Use several restrictions on one table | Create each one. Servicely runs every active restriction on the table and adds each query. On the Config tab, Order sets which runs first, lowest first. |