1. Create Record
context.createEntity(slug, payload)
async· returnsRecord<string, any>
Creates a new record in the specified entity. The created record is returned in result.values[0] and can be used immediately — for example to redirect to the new record's page.
Prop
Type
context.updateComponentByName("btnCreateInvoiceFromOffer", "loading", true);
var offerEntity = await context.getEntity("offers", context.router.id);
var offer = offerEntity.values[0];
const offerItems = offer.OfferItems || [];
var today = new Date();
const invoice = {
Company: offer.Company.ID,
InvoiceDate: today.toISOString(),
InvoiceItems: offerItems.map(item => ({
InventoryItem: item.InventoryItem.ID,
Quantity: item.Quantity,
Price: item.Price,
TotalItemAmount: item.TotalItemAmount
})),
PaymentMethod: offer.PaymentMethod.ID,
TotalAmount: offer.TotalAmount
};
var createdInvoice = await context.createEntity("invoices", invoice);
context.redirect("/invoices/" + createdInvoice.values[0].ID);
context.updateComponentByName("btnCreateInvoiceFromOffer", "loading", false);
Returned value — an object with a values array containing the newly created record, including system fields populated by the platform:
{
"values": [
{
"ID": "204",
"InvoiceNumber": "INV-2026-204",
"Company": { "ID": "5", "Name": "Acme Corp" },
"TotalAmount": 1500.00,
"InvoiceDate": "2026-03-12T10:24:00Z",
"CreateDate": "2026-03-12T10:24:00Z",
"CreateUser": { "ID": "7", "FullName": "John Smith" },
"ModifyDate": "2026-03-12T10:24:00Z",
"ModifyUser": { "ID": "7", "FullName": "John Smith" },
"SystemStatusID": { "ID": "1", "Name": "Active" }
}
]
}
Lookup fields
When building a payload, always pass the .ID of a Lookup field, not the full object. For example: Company: offer.Company.ID not Company: offer.Company. Passing the full object will cause a save error.