Autorun AI Docs

Business Functions Reference

Business functions are the server-side library available inside every business process. They all hang off context.functions:

const result = await context.functions.create("invoices", { ClientName: "Acme Corp", Amount: 1500 });
Process code written for the previous backend will not run

The old function names — CreateRecord, GetRecord, SendNotificationAsync, SendHttpRequestAsync, CallAIAsync and the rest — no longer exist, and there is no compatibility layer. Calling one fails at runtime with "is not a function". See Coming from the previous backend at the end of this page.


Three rules that apply everywhere

Every function is asynchronous. There are no synchronous variants of anything. Always await, including in loops.

The Async suffix means nothing. SendEmailAsync and create are equally asynchronous. Some names carry the suffix for historical reasons and some do not — there is no SendEmail to pair with SendEmailAsync.

Names are case-sensitive and inconsistent. Data functions are lower camel case (create, getById, generatePdf); messaging functions are PascalCase (Notify, SendEmailAsync). Copy them exactly.


Quick Reference


Every function at a glance

Data

FunctionReturns
get(slug, options?){ records, totalCount, rowCount }
getById(slug, id)the record, or null
create(slug, values){ success, id, message }
update(slug, id, values){ success, message }
delete(slug, id){ success, message }
createBulk(slug, records, options?)bulk result
updateBulk(slug, records, options?)bulk result
deleteBulk(slug, idsOrOptions, options?)bulk result

Messaging

FunctionReturns
Notify(userId, title, content, link, type)boolean
NotifyGroup(field, operator, value, title, content, link, type)boolean
BroadcastAsync(title, content, link?, type?)boolean
SendEmailAsync(to, subject, body, from)boolean
SMSNotifyAsync(phone, message)delivery result
WhatsAppNotifyAsync(phone, message)delivery result
SendFunctionToUserAsync(userId, functionId, payload?)always true
BroadcastFunctionAsync(functionId, payload?)always true

Documents and files

FunctionReturns
generatePdf(slug, id, templateId, header?, footer?)Base64 string
generateWord(slug, id, templateId)Base64 string
generateExcel(slug, fields?, filter?)Base64 string
generateExcelTemplate(values, templateId)Base64 string
GetFileAsync(fileRef){ bytes, mime, filename, size } or null

Integration

FunctionReturns
http(options){ ok, status, statusText, headers, body }
promptAgent(agentId, message)string

Sequences

These live on context.sequences, not context.functions.

FunctionReturns
context.sequences.getNext(name)number
context.sequences.getCurrent(name)number
context.sequences.exists(name)boolean
context.sequences.reset(name, value)true

Records

Records are flat objects keyed by column name in PascalCase. There is no Attributes wrapper.

{
  "ID": 84,
  "ClientName": "Acme Corp",
  "Amount": 1500.00,
  "CreateDate": "2026-03-12T10:24:00.000Z",
  "CreateUser": { "ID": 7, "FullName": "John Smith" },
  "ModifyDate": "2026-03-12T10:24:00.000Z",
  "ModifyUser": { "ID": 7, "FullName": "John Smith" },
  "SystemStatusID": 1
}

Every entity carries the six system fields ID, CreateDate, CreateUser, ModifyDate, ModifyUser, and SystemStatusID. They are managed by the platform and are stripped from any create or update payload that includes them.

Dates arrive as strings, not Date objects. Lookup fields arrive expanded as objects rather than as bare foreign keys.


Failure is usually silent

Almost nothing throws. create, update, and delete return { success: false }; http returns { ok: false }; the messaging functions return false; getById and GetFileAsync return null. Only promptAgent raises an error on its own.

const result = await context.functions.create("invoices", values);
if (!result.success) throw new Error("Could not create invoice: " + result.message);

This is the single most common source of processes that appear to work but quietly do nothing. Error Handling covers it in full.


Coming from the previous backend

Every function below was part of the original Mileva backend and has been removed. There is no shim — a call to any of them throws.

PreviousNow
CreateRecord(slug, appId, data, claims)create(slug, data) — no app id, no claims
GetRecord(...)get(slug, options) or getById(slug, id)
UpdateRecord(...)update(slug, id, data)
DeleteRecord(...)delete(slug, id)
NotifyAsync(...)Notify(...)
NotifyGroupAsync(...)NotifyGroup(...)
SendHttpRequestAsync(values), httpGet, httpPosthttp(options)
GetEncodedString(text)btoa(text)
CallAIAsync, CallAIWithAttachmentAsync, CallMilevaAsyncpromptAgent(agentId, message)
generatePDF, generatePdfStringgeneratePdf(slug, id, templateId, header?, footer?)
GenerateWordFileAsync(slug, id, userId, templateID)generateWord(slug, id, templateId)
TemplateToExcelJS, TemplateToExcelJSAsyncgenerateExcelTemplate(values, templateId)
executeFrontedFunction(userId, content)SendFunctionToUserAsync(userId, functionId, payload?)
throwError(message)throw new Error(message)
context.user.idcontext.claims.userId
context.appSlugcontext.appDbId
context.entityNamecontext.slug

Removed with no replacement: SendEmailGroup, sendEmailWithAttachments, SendTemplatedEmail, uploadFileFromUrl, GetFile, CreateFolderAsync, CreateMultipleFoldersAsync, clearCacheMeta, manuallyExecuteReadSql, manuallyExecuteNonReadSql, getBankStatements, generateInvoiceXml, validateFiscalizationDocument, and sendFiscalizationDocument.

Two more things that changed quietly

get() now returns at most 100 records by default — set pagination.take or page through the results. And group filters use { condition, predicates }; the old { operator, filters } keys are ignored rather than rejected, so a legacy filter silently matches everything.