
FileMaker developers building integrations keep asking the same question: can I lock a record through the Data API or OData and have that lock show up for everyone using the database? The short answer is no. Native locks belong to interactive clients, and the APIs are stateless. But the need is real, especially as richer interfaces move into WebViewers and the UI has to coordinate with the database through scripts.
This article describes a lease-based soft lock that works across FileMaker Pro, Go, WebDirect, WebViewers and API clients. It is my current understanding, and corrections and alternative approaches are welcome.
JSON( key = value, … ), LockResult( … ), LockTTL( … ), LockToken( ), IsServiceAccount( ) and Lock_Config( … ). These are not built-in FileMaker functions. JSON() is simply a thin wrapper around JSONSetElement() that builds an object from name/value pairs, and the others are small custom functions you define yourself. Adapt the steps and syntax to your own solution.1. Why native locks don’t cross over #
Native record locking belongs to a client that has a record in edit mode, and it lasts only as long as the edit. The Data API and OData are stateless: each request stands alone, a script run through an API ends when it returns, and neither API has a lock endpoint. FileMaker also has no built-in way to tell connected clients that a record has become locked or unlocked.
A server-side script therefore can’t hold a native lock across requests, and it can’t put a field into edit mode on behalf of an API user. What a script can do is hold a native lock for its own duration. That is useless as the lock itself, but it is exactly what we need as a short mutex that makes lock transitions atomic (section 4).
2. Design principles #
- A separate table. Lock state lives in its own
Lockstable, never as fields on the data record. Heartbeats written to the data record would bump itsmodId(breaking optimistic concurrency), collide with editors (error 301), and pollute modification timestamps, audit logs and triggers. - Leases, not locks. A lock is a lease with an expiry that the holder keeps renewing. A crashed client simply stops renewing.
- One clock, and it is the server’s. All timing uses the server’s UTC milliseconds. Client clocks are never compared. This only holds if every lock script runs on the server (see the note at the start of section 4).
- An ownership token. Acquiring returns a secret token. Renew, release and every write must present it, so a client that slept past its lease can’t act on a lock it no longer owns. The row also carries a monotonic generation number, which is the value to use if a downstream system needs a true fencing number.
- Atomic transitions. Every state change happens while the lock row is open (natively locked) inside one script. Two scripts can’t interleave their read-check-write on the same lock row.
- Enforcement by privileges. Direct writes to protected tables are denied. Writes go through scripts that check the lock.
- Two layers. The soft lock prevents concurrent editing.
modIdcatches whatever still slips through.
One consequence is worth stating early: a lease that has expired but has not been taken over is still valid, because the token proves nobody else acquired the lock in between. Expiry only decides when others may take over. Nothing in this design (including cleanup, section 4.7) may clear the token of an expired lease, or this property is lost. Only an explicit release or a takeover rotates or clears it.
3. The Locks table #
One row per lockable record, created lazily on first use.
| Field | Type | Notes |
|---|---|---|
id | Text | Primary key, auto-enter Get ( UUID ) |
lock_key | Text | target_table & "|" & target_uuid. Unique, validated “Always” (see below) |
target_table | Text | Logical name of the locked table |
target_uuid | Text | Stable UUID of the locked record (never the internal record ID) |
owner_id | Text | Account or user identity. Empty means free |
owner_name | Text | Display name for banners |
owner_client | Text | pro, go, webdirect, webviewer, api |
lock_token | Text | Random secret per acquisition, never returned by Status. See section 4.2 |
generation | Number | +1 on every acquisition. Monotonic, useful in logs and for downstream fencing |
acquired_ms, renewed_ms, expires_ms | Number | Get ( CurrentTimeUTCMilliseconds ) values. Numeric UTC avoids DST ambiguity |
renew_count | Number | Heartbeats in the current lease |
expire_logged_gen | Number | The generation for which cleanup already logged EXPIRE, so it logs once |
The unique lock_key turns a creation race into error 504 (value not unique), which the scripts treat as “someone else created it first, find it again”. Set the field’s validation to Always: FileMaker only validates script-driven changes (Set Field, imports) when the option is “Always”, not when it is “Only during data entry”. Without it, the 504 never fires and duplicate rows become possible.
Add a small LockLog table (ts_ms, lock_key, event, owner_id, generation, detail). Events: ACQUIRE, REACQUIRE, TAKEOVER, DENIED, RELEASE, EXPIRE, FORCE_RELEASE, WRITE_OK, WRITE_REJECTED. It costs almost nothing and saves hours when someone asks why a record was locked.
4. The scripts #
All scripts take a JSON parameter, return JSON through Exit Script, and have Run script with full access privileges enabled.
| |
| Code | Meaning |
|---|---|
| GRANTED, RENEWED, RELEASED, STATUS | Success |
| DENIED | Held by someone else. data has owner, since, expires |
| LOST | The token is no longer valid (released or taken over) |
| BUSY | Contention on the lock row. Retry shortly |
| IN_USE | The data record is natively locked by an editor (error 301) |
| CONFLICT | modId or expected values no longer match |
| INVALID, NOT_FOUND, ERROR | Bad input, missing record, or an unexpected FileMaker error (in data) |
Two custom functions keep the scripts short and consistent: LockTTL ( raw ) returns 90 when empty, otherwise the value clamped to 30–600 seconds, and LockToken ( ) returns Get ( UUID ) & Get ( UUID ).
4.1 Lock_Open_Row (subscript) #
Finds the lock row, creates it if allowed, and leaves it open in the current session. Everything else builds on this. It changes the layout of the server session it runs in, which is harmless there but is another reason these scripts must never run in a user’s window.
| |
4.2 Lock_Acquire #
Two details matter here. First, capture every value you return into variables before logging. Logging may move the session to another layout, after which Locks:: references can come back empty. Second, the identity rule: use the authenticated account, and accept a user from the parameter only for known service accounts (section 5).
| |
A same-user re-acquire from another session is granted and rotates the token, so the older session sees LOST on its next heartbeat. If you prefer one session per user to be strict, store and compare a session id as well.
Get ( UUID )is not documented as a cryptographically secure source, which is why the token concatenates two of them. That is fine for coordination between cooperating clients, but the soft lock is not a security boundary (section 5). If the token must resist a determined attacker, generate it in your backend from a proper random source.
4.3 Lock_Renew #
| |
4.4 Lock_Release #
| |
4.5 Lock_Status #
Read-only, used for banners and list views. It takes a list of records so a list screen costs one call, and it never returns the token.
| |
4.6 Record_Update_Guarded #
This is the only way API clients write to a protected table. It checks the token, the modId and, optionally, the original values of the fields being changed. The lock row must stay locked for the whole write, so nobody can take over, renew or release in the middle. There are two ways to achieve that. Both are sound on paper, and both should be race-tested (section 11) before you rely on them.
Variant A: two windows. The lock row stays open in the first window, and the data record is edited in a second one.
| |
Variant B: a transaction block (Open Transaction and Commit Transaction, available since FileMaker 19.6). Records modified inside the block are held until the commit, so touching the lock row inside the block keeps it locked while the data record is written, all in one window and without relying on the second-window behavior. A successful write can also extend the lease. The row must be found before the block, because creation and its commit can’t happen inside it.
| |
Transactions have rules of their own: they can’t nest (subscripts count), some errors revert the whole block automatically, and a Find inside the block sees the data as it was before the block. Read the Claris documentation for your version before building on this.
Either way, on any failure path, close the window and revert open records before exiting. The allow-list matters: without it this script is a generic write endpoint.
4.7 Lock_Cleanup and Lock_Force_Release #
Lock_Cleanup runs as a scheduled server script every few minutes. Takeover and Status already evaluate expiry from expires_ms, so cleanup does not clear anything. It only produces tidy logs and prunes old data. It must never clear lock_token or owner_id on an expired row: that would turn a lease that is still validly the holder’s into LOST, which contradicts section 2.
| |
Lock_Force_Release is for administrators: clear the row (including the token), and log FORCE_RELEASE with the real account name from Get ( AccountName ). Restrict who can run it with script execute privileges (admin privilege sets only). Don’t rely on an in-script Get ( PrivilegeSetName ) check: in a script that runs with full access privileges, that function can report the full-access set instead of the caller’s. Every stuck-lock support call ends here, so build it on day one.
5. Enforcement #
A soft lock is advisory unless the server refuses writes that skip it. For the API accounts:
- Records: view only on protected tables, and no edit, create or delete. Writes go through
Record_Update_Guarded. - Locks and LockLog: no direct access. This also keeps
lock_tokenaway from other clients, since a readable token is a bearer secret. Remember that the Data API URL needs a layout. Use an empty utility layout (for exampleAPI_Utility, based on a one-record utility table) for script calls, never a layout onLocks. - Scripts: execute access only to the
Lock_*scripts and the guarded writers. - Identity: use
Get ( AccountName )as the owner when each person has a FileMaker account. If a trusted backend calls with one shared service account, list that account inIsServiceAccount ( ). Only then is theuserparameter honoured, and the lock is exactly as trustworthy as that backend.
Anything with full access, such as admin tools and server scripts, can still bypass the lock. The same goes for FileMaker Pro users whose privilege set allows editing: unless you also block editing on the layout (section 6), a Pro user can write to the record directly. Treat the soft lock as a coordination tool for cooperating clients, not a security boundary.
6. FileMaker Pro, Go and WebDirect clients #
Native locking still protects Pro users editing at the same moment, but API clients can’t see a native lock until their write hits error 301. To make Pro users first-class participants, have them take a soft lock too. Every call goes through Perform Script on Server.
| Trigger | Action |
|---|---|
| OnRecordLoad | Lock_Status for the record. Set $$LOCKED_BY_OTHER and the banner text |
| Edit button (or first field entry) | Lock_Acquire, store $$TOKEN. On DENIED, stay read-only and show who holds it |
| OnTimer, every 30 s | Holder: Lock_Renew. On LOST, revert local edits and warn. Non-holder: Lock_Status to refresh the banner |
| Save, OnRecordRevert, OnLayoutExit, OnWindowClose | Commit if needed, then Lock_Release |
| OnRecordCommit | A last renew check. If LOST, return False to cancel the commit |
A window has only one timer, so this single script does both the heartbeat and the polling, and it can act as the dispatcher if the layout already uses a timer. Hide the edit controls or block field entry (OnObjectEnter returning False when $$LOCKED_BY_OTHER = 1) and show a banner such as “Locked by Maria since 10:42”. Polling still adds up to one timer interval of latency.
Go. A backgrounded app is suspended by the operating system, so its timer stops and the lease will lapse. That is fine, because it is the same path as a crashed client. On return to the foreground, call Lock_Renew first. If the lease lapsed but nobody took over, the token still works. If it returns LOST, treat the edit as stale exactly as you would for any other client.
WebDirect. The same triggers and timer apply. Don’t count on the close triggers when a user simply closes the browser tab or the session times out. The TTL is the safety net here too.
7. API and WebViewer clients #
A standalone script call through the Data API looks like this (the parameter is URL-encoded in practice, and scriptResult comes back as a string you parse a second time). It is a GET with side effects, so send Cache-Control: no-store, and keep in mind that very long parameters hit URL length limits.
| |
The same scripts work through OData. A script is called with a POST to Script.<name>, the parameter goes in a single scriptParameterValue field (a JSON object is accepted), and the script’s exit result comes back as resultParameter inside scriptResult. OData runs the script server-side, and it only supports scripts that need no user interaction, which is exactly what these are. Avoid special characters and leading digits in script names.
| |
Rules for a browser or WebViewer UI:
- Heartbeat at TTL/3 (30 s for a 90 s TTL), and also renew immediately on
visibilitychange, because browsers throttle timers in background tabs. - Keep the token in memory per tab. Two tabs of the same user are two sessions, and the second takes over from the first.
- On leaving the page, send a best-effort
Lock_Releasewithfetchandkeepalive: true, frompagehideandvisibilitychange(unloadis unreliable, especially on mobile).navigator.sendBeaconcan’t set the Authorization header the Data API needs, so use it only against your own backend. The TTL is the safety net either way. - A WebViewer inside a FileMaker window should not call the API itself. Have the page call a FileMaker script through
FileMaker.PerformScript, which uses the user’s own session and identity, and let the layout triggers release the lock when the layout changes, because the page’s own unload events may not fire then. - An expired Data API session (for example error 952, invalid token) is not a lost lock. Log in again and renew. If the lease lapsed untouched, the token still works.
- On LOST, freeze the form, keep the user’s changes visible, and offer to reload the record. Never retry a write silently.
- On BUSY, retry with a short randomized backoff.
8. Optimistic concurrency #
Because lock traffic lives in its own table, the data record’s modId only changes when the record itself is modified, so it is a reliable version. (Imports, server scripts and anything else that writes the record will bump it too, which is what you want.) The Data API returns it with every record, and a PATCH that includes a stale modId fails with error 306. Use it in two ways:
- Plain PATCH on tables without a lock requirement: send the
modIdyou read, and on 306 reload and retry. - Guarded writes: send the
modIdand the token together.
modId is coarse: any change to the record, even an unrelated field, causes a conflict. The expected object in Record_Update_Guarded is the finer option. The client sends the original values of the fields it is changing, and the script rejects the write only if those particular fields changed, so non-overlapping edits merge.
Two scope limits to document for your solution: portal and related records have their own modId, and a lock on a parent doesn’t cover its children by itself. To lock a whole document, make the lock key the root record, and let the guarded writers for child tables accept the root’s token.
For OData, ETag and If-Match behavior on FileMaker’s endpoint is something to test against your server version before you rely on it. If it isn’t available, call the guarded script instead.
9. Failure modes #
| Situation | Result |
|---|---|
| Client sleeps past its TTL, nobody else touched the record | Renew and write still succeed (the token matches, and cleanup never clears it). modId protects against stale data |
| Someone took over meanwhile | Renew and guarded writes return LOST |
| Holder released explicitly, stale client acts later | LOST: release clears the token |
| Client crashes, or Go is suspended, or a WebDirect tab is closed | The lease expires after the TTL and the next acquire takes over |
| Server script dies mid-transition | The session closes, the open row is released and uncommitted changes are discarded |
| FileMaker Server restarts | Rows persist and leases expire normally |
| Backup restored | The Locks table rolls back too. Clients get LOST on their next heartbeat and re-acquire. Clear the table after a restore |
| Server clock jumps (VM resume, NTP step) | Leases shorten or lengthen. Keep TTLs at 30 s or more and use gradual NTP adjustment. Worst case is an early takeover, which the old holder sees as LOST |
| Data API session expires | Re-authenticate and renew. The lease is unaffected |
| Pro user editing natively | API writes get IN_USE until the edit ends |
| Pro user bypasses the UI with edit privileges | Not prevented. See section 5 |
| Stuck lock | Lock_Force_Release |
Transaction steps (Open Transaction and Commit Transaction, FileMaker 19.6 and later) are a good fit inside Record_Update_Guarded (Variant B in section 4.6), and for multi-record writes in general. They still can’t span several API requests, so they don’t replace the lease.
10. When a soft lock isn’t enough #
FileMaker doesn’t push lock changes to clients, so every approach above has polling latency, and the lock table is a hot spot under heavy contention. If you need instant notification to WebViewer users or high lock volume, there are two directions.
- Push from FileMaker. OData webhooks (registered through the OData API, available from FileMaker Server 22.0.4) can notify an external service when records in a table change. Pointed at the Locks table, a small relay can fan changes out to browsers over WebSocket or server-sent events. Check the webhook documentation for your server version for what it supports.
- Move coordination out. Use an external service, for example Redis with
SET key value NX PX ttland pub/sub, or a small service in front of it. FileMaker scripts then call it throughInsert from URL. The trade-offs are an extra dependency and a second source of truth that must be reachable from every writer.
For most solutions the table-based design here is enough.
11. Test checklist #
A design like this is only as good as its race tests. Run them with several concurrent sessions, not by hand:
- Two clients acquire the same free lock at the same instant: exactly one gets GRANTED.
- Two scripts create the lock row for a record that has none: one row exists afterward (this fails silently if
lock_keyvalidation isn’t “Always”). - Renew after takeover returns LOST. Renew after a lapsed but untaken lease succeeds, including after
Lock_Cleanuphas run. - A guarded write with a stale token returns LOST, and a write racing with a takeover never lands after the takeover is committed.
- A guarded write while a Pro user has the record open returns IN_USE.
- A write with a stale
modId, and a write with changedexpectedfields, return CONFLICT. Non-overlapping edits throughexpectedmerge. - Kill the server script mid-write: no lock row is left open and no data is changed.
Lock_Force_Releasefails for a non-admin account.- Run every
Lock_*script from a Pro client without Perform Script on Server: it is refused.
Takeaway #
You still can’t trigger a native FileMaker lock from the Data API or OData, but you can get coordinated editing across every client with a few ingredients: a dedicated Locks table, leases renewed against the server clock, an ownership token checked on every write, lock transitions made atomic by a native lock held inside the script, privileges that force writes through those scripts, and modId as the second line of defense. Build it as coordination, enforce it on the server, test the races, and log everything.