9. Downloads
These functions trigger a file download in the user's browser, generated from a record's data merged into a stored template.
Templates are stored in the _Template entity and created via raw HTML or the Rich Text Editor (PDF/Word). Excel templates must be imported as .xlsx files. Record data is inserted using placeholders — e.g. {{Record.InvoiceNumber}} or {{Record.IssuerCompany.Name}} for Lookup fields.
context.downloadPDF(entitySlug, recordId, templateId [, fileName, footerTemplate, headerTemplate])
async· returnsvoid
Generates and downloads a PDF by merging a record's data into an HTML template.
Prop
Type
context.updateComponentByName("btnDownloadInvoice", "loading", true);
var invoiceEntity = await context.getEntity("invoices", context.router.id);
var issuerID = invoiceEntity.values[0].IssuerCompany.ID;
switch (issuerID) {
case "1":
await context.downloadPDF("invoices", context.router.id, 25);
break;
case "2":
await context.downloadPDF("invoices", context.router.id, 26);
break;
default:
await context.downloadPDF("invoices", context.router.id, 25);
}
context.updateComponentByName("btnDownloadInvoice", "loading", false);
context.downloadPDFWithBarCode(entitySlug, recordId, templateId, barCode [, fileName, footerTemplate, headerTemplate, templateValues])
async· returnsvoid
Like downloadPDF but also embeds a payment barcode into the generated PDF. Used for invoices and payment slips.
Prop
Type
BarCodeData fields:
Prop
Type
var invoice = (await context.getEntity("invoices", context.router.id)).values[0];
await context.downloadPDFWithBarCode(
"invoices",
context.router.id,
25,
{
totalAmount: invoice.TotalAmount,
customerCompany: {
name: invoice.Company.Name,
adress: invoice.Company.Address,
cityWithPostalCode: invoice.Company.City
},
issuerCompany: {
name: invoice.IssuerCompany.Name,
adress: invoice.IssuerCompany.Address,
cityWithPostalCode: invoice.IssuerCompany.City,
IBAN: invoice.IssuerCompany.IBAN
},
referenceNumber: invoice.InvoiceNumber,
paymentDescription: "Invoice payment"
},
"invoice_" + invoice.InvoiceNumber + ".pdf"
);
context.downloadWord(entitySlug, recordId, templateId [, fileName])
async· returnsvoid
Generates and downloads a Word (.docx) file by merging a record's data into a Word template.
Prop
Type
context.updateComponentByName("btnDownloadContract", "loading", true);
await context.downloadWord("contracts", context.router.id, 14, "contract.docx");
context.updateComponentByName("btnDownloadContract", "loading", false);
context.downloadExcel(payload, templateId, fileName)
async· returnsvoid
Generates and downloads an Excel (.xlsx) file by populating a stored Excel template with the provided payload values.
Prop
Type
context.updateComponentByName("btnExportReport", "loading", true);
await context.downloadExcel(
{ Month: "March 2026", TotalRevenue: 85000 },
18,
"monthly_report_march_2026.xlsx"
);
context.updateComponentByName("btnExportReport", "loading", false);
context.downloadFile(url, payload, fileName)
async· returnsvoid
Downloads a file from a custom URL, optionally posting a payload. Use this for downloading files from external APIs or custom backend endpoints.
Prop
Type
await context.downloadFile(
"/api/export/report",
{ from: "2026-01-01", to: "2026-03-31" },
"q1_report.pdf"
);