Skip to content

Example: access for HR data

View as Markdown

This walk-through builds access for HR data from the pieces on the other pages: field levels per grant, classification, record actions, restrictions that cover admins, and approvals. Use it as a pattern for any data where people see their own record, managers see their team’s, and a few fields are for HR only.

You’ll need two entities of your own (create them in Build or ship them in an app):

Entity Fields
employee name, country, phone, salary (an amount), manager (a reference to another employee), user (the login account)
leave_request employee (a reference), requested_by (a user), start, end, days, status, reason, medical

The reporting line is a hierarchy on employee.manager, here called Reporting line, with user as the field that says which employee record is you.

The people: Somchai runs the team; Mali reports to him, Niran to Mali and Ploy to Niran. Wei, in another country, also reports to Somchai. Hana works in HR.

Who Employee records Salary Leave requests Reason and medical note
An employee (Niran) their own; may change their phone only their own, in clear, with its history their own; may file and comment on their own requests: they enter them
A manager (Mali) everyone below them in the reporting line; may change a report’s country in clear with its history for everyone below them (Niran, and Ploy below him), in clear on their own record; not their own manager’s dates of their reports’ leave; may approve up to two levels down on their own requests only
HR (Hana) everyone; may change anything in clear everyone’s; may approve visible
Owner and admins everyone masked, except their own record and anyone below them in the reporting line; only HR changes pay everyone’s on their own requests only, unless they’re in HR
Anyone can’t approve or change a leave request they filed

In Settings › Access › Classification:

  • Employee: set salary to Sensitive. From now on salary is masked for everyone who isn’t an owner or admin, unless a set gives it a level.
  • Leave request: switch on Audit reads, so every time someone opens a leave request, the access audit says who.

See Data classification, masking and reveal.

Employee self-service. Two grants on rows that are “mine”. On the employee record the grant lists its field levels: salary read makes the classified salary readable on your own record only, and phone is the one field you may change.

{
"key": "hr.employee",
"label": "Employee self-service",
"grants": [
{
"entity": "employee", "ops": ["read", "update"],
"where": { "left": "{{user}}", "op": "eq", "right": "@me" },
"fields": { "phone": "write", "name": "read", "country": "read", "manager": "read", "user": "read", "salary": "read" }
},
{
"entity": "leave_request", "ops": ["read", "create"], "actions": ["comment"],
"where": { "left": "{{requested_by}}", "op": "eq", "right": "@me" }
}
]
}

Line manager. Everyone below me in the reporting line, at any depth (my direct reports, their reports and so on), with their salary in clear and only country (the job location) writable. To limit pay to direct reports, add "depth": { "max": 1 } to this grant’s condition and to the pay restriction’s exemption below; managers then see the rest of their chain without pay.

{
"key": "hr.manager",
"label": "Line manager",
"grants": [
{
"entity": "employee", "ops": ["read", "update"], "actions": ["export"],
"where": { "left": "{{id}}", "op": "in", "right": "@me.descendants", "via": "reporting_line" },
"fields": { "salary": "read", "phone": "read", "name": "read", "manager": "read", "user": "read", "country": "write" }
},
{
"entity": "leave_request", "ops": ["read"],
"where": { "left": "{{employee}}", "op": "in", "right": "@me.descendants", "via": "reporting_line" }
},
{
"entity": "leave_request", "ops": [], "actions": ["comment", "approval:decide"],
"where": { "left": "{{employee}}", "op": "in", "right": "@me.descendants", "via": "reporting_line", "depth": { "max": 2 } }
}
],
"history": { "employee": { "phone": "hidden" } }
}

HR. Everything on both entities, salary writable, the HR actions, and a capability of your own, hr.medical, that the restriction below looks for.

{
"key": "hr.hr",
"label": "HR administrator",
"grants": [
{ "entity": "employee", "ops": ["read", "create", "update"], "actions": ["export"], "fields": { "salary": "write" } },
{ "entity": "leave_request", "ops": ["read", "create", "update"], "actions": ["export", "comment", "work_note", "approval:decide"] }
],
"capabilities": ["hr.medical"]
}

You build each of these in the permission set editor: the grant’s Record actions checkboxes, its Field levels on these rows table, the set’s Hide history column and Add a capability. Or paste them in the JSON tab.

All are enforced on owners and admins, so they hold for everyone. The first two depend on the record: their field caps don’t apply on the rows that match Except on rows where (unlessWhere).

The reason and the medical note are hidden, except for HR and on a request you filed. The employee enters them when filing and reads them back; nobody else does:

{
"key": "hr.leave_medical_hr_only",
"entity": "leave_request",
"actions": [],
"fields": { "reason": "hidden", "medical": "hidden" },
"unlessCapability": "hr.medical",
"unlessWhere": { "left": "{{requested_by}}", "op": "eq", "right": "@me" },
"enforceOnAdmins": true,
"message": "Leave reasons and medical notes are for the employee and HR only."
}

Pay is masked for everyone, owners and admins included, except for HR (hr.comp), on your own record and on the records of everyone below you in the reporting line. HR viewers with pii.reveal can still reveal it with a reason (revealable):

{
"key": "hr.pay_hr_only",
"entity": "employee",
"fields": { "salary": "masked" },
"unlessCapability": "hr.comp",
"unlessWhere": { "any": [
{ "left": "{{user}}", "op": "eq", "right": "@me" },
{ "left": "{{id}}", "op": "in", "right": "@me.descendants", "via": "reporting_line" }
] },
"revealable": true,
"enforceOnAdmins": true,
"message": "Pay is for HR, the employee and the managers above them."
}

And only HR changes pay, on their own record too:

{
"key": "hr.pay_changes_hr_only",
"entity": "employee",
"fields": { "salary": "read" },
"unlessCapability": "hr.comp",
"enforceOnAdmins": true,
"message": "Only HR changes pay."
}

Give the HR set the capability hr.comp next to hr.medical.

{
"key": "hr.leave_no_self_approval",
"entity": "leave_request",
"actions": ["approval:decide", "update"],
"forbidWhen": { "left": "{{requested_by}}", "op": "eq", "right": "@me" },
"enforceOnAdmins": true,
"message": "You can't approve or change a leave request you filed yourself."
}
Role Holds
Employee hr.employee
Line manager hr.employee, hr.manager
HR administrator hr.employee, hr.hr

Every manager also holds the employee set: it shows everyone’s directory fields without pay, and their own record with it. The manager set adds pay for everyone below them. Levels are worked out per row, and the highest level any of your grants gives on that row wins: a manager reads pay on their own record and below them, and nowhere else.

  • Niran (Employee) opens his own record and sees his salary. He can change his phone; changing his salary, manager or country is refused. He sees his own leave requests and can file one.
  • Mali (Line manager) lists Niran and Ploy, who reports to Niran. Both show their salary, and their records’ history has every past salary. She doesn’t see the salary of Somchai, her own manager, or of Wei’s team next to hers. Her own record shows her salary.
  • Somchai (Line manager, two levels above Niran) may approve Niran’s leave; he can’t approve Ploy’s, which is three levels down. Wei can’t approve either: they’re not in his line.
  • Hana (HR) reads every salary, reason and medical note, and approves any leave request except one she filed herself.
  • The workspace owner and admins see salaries masked, except on their own record and for anyone below them in the reporting line (pay restriction, enforced on admins; they don’t hold hr.comp), and can’t change pay. An owner who is also the CEO is at the top of the line, so they read everyone’s pay. They see leave reasons and medical notes only on requests they filed.
  • Nobody approves or edits a leave request they filed: the restriction covers managers, HR and admins alike.

Access follows the current reporting line, kept as a precomputed table of who is below whom that’s updated on every change. When HR moves Niran (and Ploy below him) from Mali to Wei, Wei and everyone above Wei read both salaries and their whole history straight away, including the versions from before Wei became their manager. Mali no longer does, and neither does anyone above Mali who isn’t also above Wei. That’s the usual HR model: the history belongs to the employee, and whoever is above them now may read it.

The reporting line itself isn’t dated here, so the switch happens when the change is saved, not on a future effective date, and “as of” reads use today’s line. A reporting line can’t loop: saving a manager who reports to the person is refused, so nobody ends up above their own manager.

unlessWhere takes the same conditions as a grant’s where: @me ({{user}} = @me, {{requested_by}} = @me), your attributes and groups, and the reporting line (in @me.descendants via …: everyone below; add depth to limit it, { "max": 1 } for direct reports only). It works on any entity of any app. Lists, related lists, search, exports, the REST API, the CLI, MCP and the assistant all apply the level for each row. Filters and sorts use the level that holds on every row you can see, so a filter on salary matches nothing when salary is masked or hidden on some of your rows, even if it’s in clear on others: a manager can’t find out a colleague’s pay outside their own line by filtering or sorting.

A list total is shown when every row it adds up is in clear for you, and left out as soon as one row is masked or hidden. A manager whose list holds only her line sees its salary total; filter her list to her team (by person or department, not by salary) and the total of that team shows too. Add one person outside her line and the total goes. The same goes for each group’s subtotal. Money totals stay per currency.

Export is a record action, so only sets that grant export allow it once any set does: here managers (for their line) and HR. An export contains exactly what the person can read: Mali’s CSV of employees lists Niran and Ploy with their salaries, and an admin’s CSV of leave requests has no reasons or medical notes.

A compensation reviewer needs a report’s salary now and then. Give them a set with read on employee and the capability pii.reveal: they see the masked salary with a Reveal button, type a reason, and the value shows once. The reveal is in the access audit with the reason, never with the value. See Reveal a masked value.

  • Use View as to open the employee list as Mali, then as Niran.
  • On a leave request, More actions › Why can I see this? shows which fields are masked or hidden for you and which restriction does it.
  • Settings › Access › Audit lists the record reads of leave requests and every reveal.
  • Before applying any of the sets, Plan shows who gains or loses what (see Reviewing access changes).