↓Skip to main content
Isometric illustration of FileMaker development workflows — an FM database at the center connected to clients, servers and devices
A lease-based soft lock that works across FileMaker Pro, Go, WebDirect, WebViewers and API clients.

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.

Warning: the FileMaker scripts in this article are pseudocode, simplified for clarity. They also use pseudo custom functions such as 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 #

Soft lock in 4 steps
Open the interactive map to explore the details

  1. A separate table. Lock state lives in its own Locks table, never as fields on the data record. Heartbeats written to the data record would bump its modId (breaking optimistic concurrency), collide with editors (error 301), and pollute modification timestamps, audit logs and triggers.
  2. Leases, not locks. A lock is a lease with an expiry that the holder keeps renewing. A crashed client simply stops renewing.
  3. 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).
  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.
  5. 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.
  6. Enforcement by privileges. Direct writes to protected tables are denied. Writes go through scripts that check the lock.
  7. Two layers. The soft lock prevents concurrent editing. modId catches 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.

FieldTypeNotes
idTextPrimary key, auto-enter Get ( UUID )
lock_keyTexttarget_table & "|" & target_uuid. Unique, validated “Always” (see below)
target_tableTextLogical name of the locked table
target_uuidTextStable UUID of the locked record (never the internal record ID)
owner_idTextAccount or user identity. Empty means free
owner_nameTextDisplay name for banners
owner_clientTextpro, go, webdirect, webviewer, api
lock_tokenTextRandom secret per acquisition, never returned by Status. See section 4.2
generationNumber+1 on every acquisition. Monotonic, useful in logs and for downstream fencing
acquired_ms, renewed_ms, expires_msNumberGet ( CurrentTimeUTCMilliseconds ) values. Numeric UTC avoids DST ambiguity
renew_countNumberHeartbeats in the current lease
expire_logged_genNumberThe 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 #

Record locking sequence
Open the interactive map to explore the details

All scripts take a JSON parameter, return JSON through Exit Script, and have Run script with full access privileges enabled.

1
{ "ok": 1, "code": "GRANTED", "message": "", "data": { ... } }
CodeMeaning
GRANTED, RENEWED, RELEASED, STATUSSuccess
DENIEDHeld by someone else. data has owner, since, expires
LOSTThe token is no longer valid (released or taken over)
BUSYContention on the lock row. Retry shortly
IN_USEThe data record is natively locked by an editor (error 301)
CONFLICTmodId or expected values no longer match
INVALID, NOT_FOUND, ERRORBad 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Lock_Open_Row   param: { key, table, id, create }
Set Error Capture [ On ]
Set Variable [ $p ; Get ( ScriptParameter ) ]
Set Variable [ $key ; JSONGetElement ( $p ; "key" ) ]
Set Variable [ $create ; GetAsNumber ( JSONGetElement ( $p ; "create" ) ) ]
Go to Layout [ "Locks" ]
Set Variable [ $try ; 0 ]
Loop
  Set Variable [ $try ; $try + 1 ]
  Exit Loop If [ $try > 6 ]
  Enter Find Mode [ Pause: Off ]
  Set Field [ Locks::lock_key ; "==" & $key ]
  Perform Find [ ]
  If [ Get ( LastError ) = 401 ]                # no row yet
    If [ not $create ]
      Exit Script [ "MISSING" ]
    End If
    New Record/Request
    Set Field [ Locks::lock_key ; $key ]
    Set Field [ Locks::target_table ; JSONGetElement ( $p ; "table" ) ]
    Set Field [ Locks::target_uuid ; JSONGetElement ( $p ; "id" ) ]
    Commit Records/Requests [ No dialog ]
    If [ Get ( LastError ) ≠ 0 ]                # 504: another script created it first
      Revert Record/Request [ No dialog ]
    End If
  Else
    Open Record/Request
    If [ Get ( LastError ) = 0 ]
      Exit Script [ "OK" ]
    End If
    # 301: another script holds the row right now (milliseconds)
    Pause/Resume Script [ Duration (seconds): 0.15 ]
  End If
End Loop
Exit Script [ "BUSY" ]

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Lock_Acquire   param: { table, id, user, name, client, ttl }
Set Error Capture [ On ]
Set Variable [ $in ; Get ( ScriptParameter ) ]
Set Variable [ $table ; JSONGetElement ( $in ; "table" ) ]
Set Variable [ $id ; JSONGetElement ( $in ; "id" ) ]
Set Variable [ $user ; Case ( IsServiceAccount ( Get ( AccountName ) ) ;
                         JSONGetElement ( $in ; "user" ) ;
                         Get ( AccountName ) ) ]
Set Variable [ $ttl ; LockTTL ( JSONGetElement ( $in ; "ttl" ) ) ]
If [ IsEmpty ( $table ) or IsEmpty ( $id ) or IsEmpty ( $user ) ]
  Exit Script [ LockResult ( 0 ; "INVALID" ; "table, id and user are required" ; "" ) ]
End If
Set Variable [ $key ; $table & "|" & $id ]

Perform Script [ "Lock_Open_Row" ; Parameter: JSON ( key = $key, table = $table, id = $id, create = 1 ) ]
If [ Get ( ScriptResult ) ≠ "OK" ]
  Exit Script [ LockResult ( 0 ; "BUSY" ; "Lock table busy, retry" ; "" ) ]
End If

# The row is open, so these values are current and nobody else can change them
Set Variable [ $now ; Get ( CurrentTimeUTCMilliseconds ) ]
Set Variable [ $held ; not IsEmpty ( Locks::owner_id ) and Locks::expires_ms > $now ]

If [ $held and Locks::owner_id ≠ $user ]
  Set Variable [ $out ; LockResult ( 0 ; "DENIED" ; "Locked by another user" ;
      JSON ( owner = Locks::owner_name, since = Locks::acquired_ms, expires = Locks::expires_ms ) ) ]
  Set Variable [ $gen ; Locks::generation ]
  Revert Record/Request [ No dialog ]
  Perform Script [ "Lock_Log" ; Parameter: JSON ( key = $key, event = "DENIED", owner = $user, generation = $gen ) ]
  Exit Script [ $out ]
End If

Set Variable [ $event ; Case ( IsEmpty ( Locks::owner_id ) ; "ACQUIRE" ;
                               Locks::owner_id = $user ; "REACQUIRE" ;
                               "TAKEOVER" ) ]
Set Variable [ $token ; LockToken ( ) ]
Set Variable [ $gen ; Locks::generation + 1 ]
Set Variable [ $exp ; $now + $ttl * 1000 ]
Set Field [ Locks::owner_id ; $user ]
Set Field [ Locks::owner_name ; JSONGetElement ( $in ; "name" ) ]
Set Field [ Locks::owner_client ; JSONGetElement ( $in ; "client" ) ]
Set Field [ Locks::lock_token ; $token ]                    # a new token invalidates any previous holder
Set Field [ Locks::generation ; $gen ]
Set Field [ Locks::acquired_ms ; $now ]
Set Field [ Locks::renewed_ms ; $now ]
Set Field [ Locks::expires_ms ; $exp ]
Set Field [ Locks::renew_count ; 0 ]
Commit Records/Requests [ No dialog ]
If [ Get ( LastError ) ≠ 0 ]
  Set Variable [ $err ; Get ( LastError ) ]
  Revert Record/Request [ No dialog ]
  Exit Script [ LockResult ( 0 ; "ERROR" ; "Commit failed" ; JSON ( error = $err ) ) ]
End If
Perform Script [ "Lock_Log" ; Parameter: JSON ( key = $key, event = $event, owner = $user, generation = $gen ) ]
Exit Script [ LockResult ( 1 ; "GRANTED" ; "" ;
    JSON ( token = $token, generation = $gen, expires = $exp, ttl = $ttl ) ) ]

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 #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Lock_Renew   param: { table, id, token, ttl }
Set Error Capture [ On ]
Set Variable [ $in ; Get ( ScriptParameter ) ]
Set Variable [ $key ; JSONGetElement ( $in ; "table" ) & "|" & JSONGetElement ( $in ; "id" ) ]
Set Variable [ $token ; JSONGetElement ( $in ; "token" ) ]
Set Variable [ $ttl ; LockTTL ( JSONGetElement ( $in ; "ttl" ) ) ]
Perform Script [ "Lock_Open_Row" ; Parameter: JSON ( key = $key, create = 0 ) ]
Set Variable [ $r ; Get ( ScriptResult ) ]
If [ $r = "BUSY" ]
  Exit Script [ LockResult ( 0 ; "BUSY" ; "Lock table busy, retry" ; "" ) ]
End If
If [ $r = "MISSING" or IsEmpty ( $token ) or Locks::lock_token ≠ $token ]
  If [ $r = "OK" ]
    Revert Record/Request [ No dialog ]
  End If
  Exit Script [ LockResult ( 0 ; "LOST" ; "Lock was released or taken over" ; "" ) ]
End If
# A matching token proves nobody took over, even if the lease has lapsed
Set Variable [ $now ; Get ( CurrentTimeUTCMilliseconds ) ]
Set Variable [ $exp ; $now + $ttl * 1000 ]
Set Field [ Locks::renewed_ms ; $now ]
Set Field [ Locks::expires_ms ; $exp ]
Set Field [ Locks::renew_count ; Locks::renew_count + 1 ]
Commit Records/Requests [ No dialog ]
Exit Script [ LockResult ( 1 ; "RENEWED" ; "" ; JSON ( expires = $exp ) ) ]

4.4 Lock_Release #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Lock_Release   param: { table, id, token }
Set Error Capture [ On ]
Set Variable [ $in ; Get ( ScriptParameter ) ]
Set Variable [ $key ; JSONGetElement ( $in ; "table" ) & "|" & JSONGetElement ( $in ; "id" ) ]
Set Variable [ $token ; JSONGetElement ( $in ; "token" ) ]
Perform Script [ "Lock_Open_Row" ; Parameter: JSON ( key = $key, create = 0 ) ]
Set Variable [ $r ; Get ( ScriptResult ) ]
If [ $r = "MISSING" ]
  Exit Script [ LockResult ( 1 ; "RELEASED" ; "Nothing to release" ; "" ) ]     # idempotent
End If
If [ $r = "BUSY" ]
  Exit Script [ LockResult ( 0 ; "BUSY" ; "Lock table busy, retry" ; "" ) ]
End If
If [ IsEmpty ( $token ) or Locks::lock_token ≠ $token ]
  Revert Record/Request [ No dialog ]                       # never touch someone else's lock
  Exit Script [ LockResult ( 0 ; "LOST" ; "Not the current holder" ; "" ) ]
End If
Set Variable [ $gen ; Locks::generation ]
Set Variable [ $owner ; Locks::owner_id ]
Set Field [ Locks::owner_id ; "" ]                          # also clear owner_name, owner_client,
Set Field [ Locks::lock_token ; "" ]                        # acquired_ms, renewed_ms, expires_ms
Commit Records/Requests [ No dialog ]                       # generation is kept
Perform Script [ "Lock_Log" ; Parameter: JSON ( key = $key, event = "RELEASE", owner = $owner, generation = $gen ) ]
Exit Script [ LockResult ( 1 ; "RELEASED" ; "" ; "" ) ]

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.

1
2
3
4
5
6
7
8
9
# Lock_Status   param: { items: [ { table, id }, ... ] }
Set Variable [ $now ; Get ( CurrentTimeUTCMilliseconds ) ]
For each item:
  Find Locks::lock_key == table & "|" & id            # no Open Record needed
  If found and owner_id is not empty and expires_ms > $now
    append { id, locked = 1, owner = owner_name, client = owner_client, since = acquired_ms, expires = expires_ms }
  Else
    append { id, locked = 0 }
Exit Script [ LockResult ( 1 ; "STATUS" ; "" ; $array ) ]

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Record_Update_Guarded   param: { table, id, token, modId, fields: {…}, expected: {…} }
Set Variable [ $cfg ; Lock_Config ( $table ) ]     # layout, uuid field, allow-list of writable fields
Open the lock row (create = 0) in this window
If [ missing or Locks::lock_token ≠ $token ]
  Revert Record/Request ; Log WRITE_REJECTED
  Exit Script [ LockResult ( 0 ; "LOST" ; "Lock is not held by this token" ; "" ) ]
End If
# The lock row stays open for the whole write.
# Use a second window for the data record. Changing layout in this window would commit the lock row.
New Window [ Name: "data" ]
Go to Layout [ $cfg.layout ]
Find where $cfg.uuidField == $id          # 401 -> NOT_FOUND
Open Record/Request
If [ Get ( LastError ) = 301 ]
  Close Window ; Revert the lock row
  Exit Script [ LockResult ( 0 ; "IN_USE" ; "Someone is editing this record" ; "" ) ]
End If
If [ not IsEmpty ( $modId ) and Get ( RecordModificationCount ) ≠ $modId ]
  → CONFLICT, with the current modId in data
End If
For each key in JSONListKeys ( $expected ):
  If GetField ( key ) ≠ expected value → CONFLICT, listing the field names
For each key in JSONListKeys ( $fields ):
  If key is not in $cfg.allowed → INVALID
  Set Field By Name ( $table & "::" & key ; JSONGetElement ( $fields ; key ) )
Commit Records/Requests [ No dialog ]
If [ Get ( LastError ) ≠ 0 ] → Revert, ERROR with the error code (validation errors included)
Set Variable [ $newMod ; Get ( RecordModificationCount ) ]
Close Window ; Revert the lock row (nothing changed in it) ; Log WRITE_OK
Exit Script [ LockResult ( 1 ; "OK" ; "" ; JSON ( modId = $newMod ) ) ]

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Same parameters as Variant A
Perform Script [ "Lock_Open_Row" ; … create = 0 ]        # find (and open) the row, outside the block
Check token → LOST                                        # Revert Record/Request before exiting
Open Transaction [ ]
  Set Field [ Locks::renewed_ms ; $now ]                  # touch the row so it is part of the transaction
  Go to Layout [ $cfg.layout ] ; Find ; Open Record/Request    # 301 → revert the transaction, IN_USE
  Check modId and expected → revert the transaction, CONFLICT
  Set the allowed fields
Commit Transaction [ ]
Get ( LastError ) ≠ 0 → ERROR (the transaction was not committed)

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.

1
2
3
4
5
6
7
Find Locks where owner_id is not empty and expires_ms < Get ( CurrentTimeUTCMilliseconds ) - 10000
                 and expire_logged_gen ≠ generation
Loop: Open Record/Request
      re-check that it is still expired and the generation is unchanged (a renewal or takeover may have arrived)
      → Set expire_logged_gen = generation, Commit, Log EXPIRE
Delete LockLog rows older than 30 days
Optionally delete Locks rows that are free (owner_id empty) and idle for 90 days; they are re-created lazily

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_token away 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 example API_Utility, based on a one-record utility table) for script calls, never a layout on Locks.
  • 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 in IsServiceAccount ( ). Only then is the user parameter 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.

TriggerAction
OnRecordLoadLock_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 sHolder: Lock_Renew. On LOST, revert local edits and warn. Non-holder: Lock_Status to refresh the banner
Save, OnRecordRevert, OnLayoutExit, OnWindowCloseCommit if needed, then Lock_Release
OnRecordCommitA 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.

1
2
GET /fmi/data/vLatest/databases/CRM/layouts/API_Utility/script/Lock_Acquire
    ?script.param={"table":"Invoices","id":"3F2A…","name":"Maria","client":"webviewer","ttl":90}

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.

1
2
3
4
POST /fmi/odata/v4/CRM/Script.Lock_Acquire
{ "scriptParameterValue": { "table": "Invoices", "id": "3F2A…", "name": "Maria", "client": "api", "ttl": 90 } }

→ { "scriptResult": { "code": 0, "resultParameter": "{\"ok\":1,\"code\":\"GRANTED\", …}" } }

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_Release with fetch and keepalive: true, from pagehide and visibilitychange (unload is unreliable, especially on mobile). navigator.sendBeacon can’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 modId you read, and on 306 reload and retry.
  • Guarded writes: send the modId and 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 #

SituationResult
Client sleeps past its TTL, nobody else touched the recordRenew and write still succeed (the token matches, and cleanup never clears it). modId protects against stale data
Someone took over meanwhileRenew and guarded writes return LOST
Holder released explicitly, stale client acts laterLOST: release clears the token
Client crashes, or Go is suspended, or a WebDirect tab is closedThe lease expires after the TTL and the next acquire takes over
Server script dies mid-transitionThe session closes, the open row is released and uncommitted changes are discarded
FileMaker Server restartsRows persist and leases expire normally
Backup restoredThe 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 expiresRe-authenticate and renew. The lease is unaffected
Pro user editing nativelyAPI writes get IN_USE until the edit ends
Pro user bypasses the UI with edit privilegesNot prevented. See section 5
Stuck lockLock_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 ttl and pub/sub, or a small service in front of it. FileMaker scripts then call it through Insert 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:

  1. Two clients acquire the same free lock at the same instant: exactly one gets GRANTED.
  2. Two scripts create the lock row for a record that has none: one row exists afterward (this fails silently if lock_key validation isn’t “Always”).
  3. Renew after takeover returns LOST. Renew after a lapsed but untaken lease succeeds, including after Lock_Cleanup has run.
  4. A guarded write with a stale token returns LOST, and a write racing with a takeover never lands after the takeover is committed.
  5. A guarded write while a Pro user has the record open returns IN_USE.
  6. A write with a stale modId, and a write with changed expected fields, return CONFLICT. Non-overlapping edits through expected merge.
  7. Kill the server script mid-write: no lock row is left open and no data is changed.
  8. Lock_Force_Release fails for a non-admin account.
  9. 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.