# Locked periods

> What happens when a change reaches into a period that is closed, such as a payroll month that has been paid.

Source: https://docs.ligament.ai/guides/effective-dating/locked-periods/

A locked period protects dates that are already closed, for example months your payroll has paid. A lock applies to one group of one entity, through a date: “Pay is locked through 31 October”. Changes that would alter a value on or before that date are refused unless the person making them has the right to change the past.

## How locks are set

Ligament sets locks up for you. To lock a group through a date, or to move a lock, email hello@ligament.ai with the entity, the group and the date. You can’t set or move a lock from the app or the API.

A lock records the date it runs through, who or what set it, and why. These appear in the error people get when a change hits the lock.

## What a lock does to writes

Ligament works out the earliest date whose values a write would change. That covers changes, corrections and rescinds, including later versions a change carries forward into. If that date is on or before the lock date:

-   Without the `effective.retro` capability, the write is refused and nothing is saved.
-   With `effective.retro` (owners and admins have it), the write needs a reason. It’s saved, and every version it writes is flagged `retro: true`.

Writes that only change dates after the lock are not affected. A raise scheduled for next month goes through as usual.

### The error

A refused write answers 422 with the code `effective_locked`:

| Field | Contains |
| --- | --- |
| `code` | `effective_locked` |
| `message` | `<Group> is locked through <date>`, followed by `(set by <who>)` when the lock records who set it. |
| `details` | `lockedThrough` (the date), `setBy` and `reason` as stored on the lock. |
| `fix` | `Changing a locked period needs the effective.retro capability and a reason.` |

If you have `effective.retro` but leave out the reason, you get `effective_reason_required` instead.

### How a retro change shows

A change that went through a lock is easy to find afterwards:

-   In the record’s [history](https://docs.ligament.ai/guides/effective-dating/as-of/index.md#a-records-history), its versions have `"retro": true`.
-   In the [changes feed](https://docs.ligament.ai/guides/effective-dating/as-of/index.md#the-changes-feed-for-exports), the change has `"retro": true`, so an export can treat it as an adjustment to a closed period.

## Locks and the back-dating limit

Each group also has a back-dating limit, such as 90 days for pay. The two work independently:

| Compared | Back-dating limit | Locked period |
| --- | --- | --- |
| Measured from | Today, counting back a number of days | A fixed date |
| Moves on its own | Yes, every day | No, only when the lock is moved |
| Without `effective.retro` | `effective_backdate_needs_capability` | `effective_locked` |
| With `effective.retro` | Allowed | Allowed, with a reason, flagged `retro` |

Give `effective.retro` to the few people who correct closed periods, such as payroll administrators, through a [permission set](https://docs.ligament.ai/guides/access/roles-and-permission-sets/index.md).
