Restrict which records a role can see
Limit a role 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 may read a table but should see only some of its records. This task is for administrators. Permissions decide which tables and fields a user can use, and a restriction narrows the records within a table.
Before you begin
- You need
administrator. - Decide which role the restriction applies to. You can use an existing role or create one under Administration → Permissions & Security → Roles.
- Make sure a permission lets that role read the table. See Permissions: table, field and transition.
Steps
When anyone queries a table, Servicely looks for active table record restrictions on it. This includes opening a record from a link. Each restriction’s Query script runs. If the script sets answer to a query, Servicely adds that query to the user’s own. If the script does not set answer, nothing is added.
-
Go to Administration → Permissions & Security → Table record restrictions and select New.
-
Enter a Name and a Description, and select the Table.
-
Write the Query script. Check the user’s roles or groups, and set
answeronly for users who should be restricted. See the example below. -
Turn on Active and save.
-
Give the role to the users who should be restricted, directly or through a group.
-
Impersonate one of those users and open the table to confirm what they see. See Impersonate a user.
| Field | Required | What to enter |
|---|---|---|
| Name | Yes | A name that says what is restricted, for example “Incident - Record visibility restrictions”. |
| Description | Yes | What the restriction does and for whom. |
| Table | Yes | The table to restrict. |
| Query | Yes | A script that sets answer to the query to add. |
| Active | No | When on, the restriction runs on every query of the table. |
| Order | No | The order among restrictions on the same table. |
Example query
The ITSM application ships this restriction on Incident. A user who can read incidents but does not hold itsm_agent sees only 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())
);
}
Result
Users the script restricts see only the matching records, wherever the table is queried, including direct links. Other users see the table as before. A restriction adds to permissions and tenancy, and never widens what a user can see.