Skip to content

Edit a record and save a new version

Save an edited record as its next version. The earlier versions stay readable.

Who can do this: a member of the record’s key domain whose role includes Save.

The samples use the allowed helper from Access decisions.

1. Open the record

Keep version. It is the base of your edit.

const opened = await allowed(await client.objects.open({ locator }));
if (opened?.kind !== 'record') return;
const fields = edit(opened.fields); // your editor

2. Save with the base version

const result = await client.objects.save(
locator,
{ kind: 'record', name: 'Visit note', fields },
{ baseVersion: opened.version },
);

3. Handle the outcome, then close

The result is one of three:

ResultMeaningWhat to do
savedThe new version exists.Show its version.
base-movedSomeone saved after your base version.Ask the person, then call saveAnyway() or abandon().
a draftThe device is offline.Tell the person. The SDK sends it later.
if (!('outcome' in result)) return tellOffline(result.draftId);
const answer = await allowed(result);
if (answer?.kind === 'base-moved') {
if (await askPerson(`Version ${answer.currentVersion} was saved meanwhile. Save anyway?`)) render(await answer.saveAnyway());
else answer.abandon();
} else if (answer) render(answer);
opened.close(); // discards the plaintext and its keys

Next