Autorun AI Docs

4. Update Record


update(slug, id, values)

async · returns { success, message }

Updates one record. Only the fields present in values are written — everything else is left alone.

Prop

Type

const result = await context.functions.update("orders", context.record.ID, {
  Status: "shipped",
  TrackingNumber: "1Z999AA1234567"
});

if (!result.success) throw new Error("Update failed: " + result.message);

Returned value

{
  "success": true,
  "message": "Record updated successfully"
}
The updated record is not returned

update reports only whether the write succeeded. To work with the new state of the row, read it back with getById.

await context.functions.update("orders", 55, { Status: "shipped" });
const order = await context.functions.getById("orders", 55);
log(order.ModifyDate);

ModifyDate and ModifyUser are stamped automatically, and any system field you include in values is stripped before the write.


Updating many records

Use updateBulk for more than one row. See Bulk Operations.


Updating the record that triggered the process

Inside a Before* process, do not call update on the record being saved. The write has not happened yet, so you would be updating stale data and triggering a second, nested write. Assign to context.record instead and the platform persists your change as part of the original operation:

/** @event beforeCreate */
context.record.Reference = "INV-" + await context.sequences.getNext("invoice-numbers");
context.record.Status = "draft";

In an After* process the row already exists, so update is the right tool — but be aware it fires the update triggers again. Guard against a loop:

/** @event afterCreate */
if (!context.record.Reference) {
  await context.functions.update(context.slug, context.record.ID, {
    Reference: "INV-" + context.record.ID
  });
}

Failure handling

Like create, update resolves with success: false instead of throwing when the write is rejected. Always check the result, or the process will carry on as though it had worked.