Autorun AI Docs

5. Delete Record


delete(slug, id)

async · returns { success, message }

Deletes one record.

Prop

Type

const result = await context.functions.delete("temporaryitems", context.record.ID);
if (!result.success) throw new Error("Delete failed: " + result.message);

Returned value

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

delete reports only success or failure. If you need the row's values — for an audit entry, or to cascade to related records — read it before deleting.

const item = await context.functions.getById("contracts", contractId);
if (!item) return;

await context.functions.create("auditlog", {
  Action: "delete",
  EntitySlug: "contracts",
  RecordId: item.ID,
  Snapshot: JSON.stringify(item)
});

await context.functions.delete("contracts", contractId);

A cleaner alternative for auditing is a BeforeDelete process, where context.record already holds the record as it was:

/** @event beforeDelete @entity contracts */
await context.functions.create("auditlog", {
  Action: "delete",
  RecordId: context.record.ID,
  Snapshot: JSON.stringify(context.record)
});

Deleting many records

Use deleteBulk, which accepts either a list of IDs or a filter. See Bulk Operations.


Blocking a delete

Throwing inside a BeforeDelete process cancels the deletion and surfaces your message to the caller:

/** @event beforeDelete @entity clients */
const orders = await context.functions.get("orders", {
  filter: { field: "ClientId", operator: "equal", value: context.record.ID },
  pagination: { skip: 0, take: 1 }
});

if (orders.totalCount > 0) {
  throw new Error("This client still has " + orders.totalCount + " orders and cannot be deleted.");
}