---
title: "Restrict which records a user can see"
site: admin
version: 2027.1
versions: "all"
url: https://docs-new.servicely.ai/admin/2027.1/access/roles-and-permissions/restrict-which-records-a-user-can-see/
type: task
application: platform
last_updated: 2026-12-03
commit: 8d233372fa05
---


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 `administrator` role.
- 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](page:access/roles-and-permissions/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

<Steps>
  <Step>
    Go to **Access & security → Roles & permissions → Table record restrictions**.

    <Image src="asset:screenshots/admin/access-roles-and-permissions-restrict-which-records-a-user-can-see/table-record-restrictions-menu.png">The Table record restrictions item in the Access & security menu.</Image>
  </Step>
  <Step>
    Select **New**.

    <Image src="asset:screenshots/admin/access-roles-and-permissions-restrict-which-records-a-user-can-see/new-table-record-restriction.png">The empty Create Table record restriction form, with Name, Description, Table, the Config tab and Query.</Image>
  </Step>
  <Step>
    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 |
  </Step>
  <Step>
    Write the **Query** script. Set `answer` to the query to add for the users you restrict, and leave it unset for everyone else. This script is the default Incident restriction. Users without `itsm_agent` keep only the incidents where they are the **Requestor** or the **Requested for**.

    ```javascript
    if (!user.hasRole("itsm_agent")) {
        answer = OR(
            EQUAL("Requestor", user.getID()),
            EQUAL("RequestedFor", user.getID())
        );
    }
    ```

    <Image src="asset:screenshots/admin/access-roles-and-permissions-restrict-which-records-a-user-can-see/incident-restriction.png">The default Incident restriction, with Name, Description, Table, the Config tab and its Query script.</Image>
  </Step>
  <Step>
    On the **Config** tab, set **Active** to Yes. A new restriction is not active.
  </Step>
  <Step>
    Select **Create**.
  </Step>
  <Step>
    Impersonate a user the script restricts and open the table to confirm what they see. See [Impersonate a user](page:access/roles-and-permissions/impersonate-a-user).
  </Step>
</Steps>

## 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. |

## Related

- [Permissions](page:access/roles-and-permissions/permissions)
- [Roles](page:access/roles-and-permissions/roles)
- [Impersonate a user](page:access/roles-and-permissions/impersonate-a-user)
- [Multi-tenancy](page:access/roles-and-permissions/multi-tenancy)
