Manual

Manual · The book

Record locking

Two people, one record — how it is handled automatically, and by hand from a script.

Single-user: nothing to think about

On a single-user application a lock is granted the instant it is asked for — there is nobody to contend with. Everything below is invisible and free there; it matters the moment a project is built with Neuridion PRO as a Client/Server pair.

Automatic — the whole model, and you write no code for it

Locking is pessimistic and never waits: a record is granted at once or refused at once, and a refusal names who holds it.

You do not switch this on. Build the pair with PRO and it is simply how editing behaves; a single-user build acts as if every lock is always yours.

The Locks page: one row per held record
What is held right now, by whom and since when — with Release… for the desk that is still connected but has walked away.

By hand — from a script

Sometimes a script, not a form, is the one changing a record — or one action has to hold a record across several writes. Three methods on a record do it, speaking to the same server ledger the forms use:

// A "Book" button on the invoice form: hold the record
// while we change it — but only if nobody else is editing it.
const invoice = form.record;
if (invoice.lock()) {
    invoice.status = "booked";
    invoice.save();          // saving releases the lock by itself
} else {
    messages.alert("Being edited by " + invoice.lockedBy()
                   + " — try again in a moment.");
}

You rarely need this — the automatic form lock covers ordinary editing. Reach for it when a script changes records without a form, or when one action must hold a record for several writes in a row. A saved record's lock is already gone, so an explicit unlock() is only for the case where you locked but then decided not to save.