Autorun AI Docs

2. Create Record


context.sdk.entities.create({ params, json })

async · returns { success, id, message }

Inserts a single record.

Prop

Type

context.component.updateByName("btnCreateInvoiceFromOffer", "loading", true);

try {
  const result = await context.sdk.entities.getById({
    params: { entitySlug: "offers", recordId: context.router.id }
  });
  const offer = result?.data ?? result;

  const created = await context.sdk.entities.create({
    params: { entitySlug: "invoices" },
    json: {
      Company: offer.Company.ID,
      InvoiceDate: new Date(),
      TotalAmount: offer.TotalAmount,
      OfferId: offer.ID
    }
  });

  if (!created.success) throw new Error(created.message || "Create failed");

  context.toast.success("Invoice created.");
  context.redirect("/invoices/" + created.id);
} catch (error) {
  context.toast.error(error.message);
} finally {
  context.component.updateByName("btnCreateInvoiceFromOffer", "loading", false);
}

Returned value

{
  "success": true,
  "id": 84,
  "message": "Record created successfully"
}
You get an id, not the record

create returns a small result object — not the saved row. The new primary key is on the lowercase id property (everywhere else the platform uses uppercase ID). If you need the full record, read it back with getById.

const created = await context.sdk.entities.create({
  params: { entitySlug: "invoices" },
  json: { ClientName: "Acme Corp" }
});
if (!created.success) throw new Error(created.message);

const invoice = await context.sdk.entities.getById({
  params: { entitySlug: "invoices", recordId: String(created.id) }
});

Lookup fields

When building a payload, always pass the .ID of a Lookup field, not the full object.

/* correct */
{ Company: offer.Company.ID }

/* wrong — will fail to save */
{ Company: offer.Company }

Relationship IDs are numeric. Dates take a Date object (or an ISO string). Do not pass ID, CreateDate, CreateUser, ModifyDate, ModifyUser, or SystemStatusID — they are managed by the platform.


Failure handling

create does not always throw. Check success before using id, and wrap the call in try/catch for network and permission errors.

The UI refreshes on its own after a successful create. You do not need a separate cache call.