record_create()
Create a new record in a table.
Syntax
record_create(table, data, opts?)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
table |
string | yes | Table name or database table id. |
data |
array | yes | Field values keyed by field id (e.g. ["name" => "Acme"]). |
opts |
array | no | Options. ["silent" => true] suppresses notifications to the new record's followers. |
Returns
The created record as an array (fields keyed by field id, plus _meta with the new id and title).
Example
$new = record_create("contacts", [
"name" => "Jane Doe",
"email" => "jane@example.com",
"status" => "lead"
]);
sys_log("Created contact #" . $new["_meta"]["id"]);
Example output
[
"name" => "Jane Doe",
"email" => "jane@example.com",
"status" => "lead",
"_meta" => ["id" => 412, "title" => "Jane Doe"]
]
Setting file fields
A file field's value is an array of file items. You can populate one without a manual upload — fetch from a URL, build from base64, or copy a file off another record:
record_create("documents", [
"title" => "Q3 Report",
// fetch from a URL
"pdf" => ["url" => "https://example.com/q3.pdf", "name" => "q3.pdf"](/help/q3-pdf-name-q3-pdf),
// build from base64 (raw base64 or a data: URI)
"cover" => ["data" => $base64String, "name" => "cover.png", "type" => "image/png"](/help/png),
// or copy a file off another record (stored as an independent copy)
"logo" => record_get("settings", 1)["logo"]
]);
URL items are fetched server-side (public HTTP/HTTPS only, max 50 MB); copied files
become independent copies. If any file can't be fetched, decoded, or copied, the whole
record_create fails. See File Fields.
Notes
- Don't include the key (id) field in
data— it's assigned automatically. - The change is recorded in activity history but does not trigger other automations.
["silent" => true]mutes follower notifications only; users assigned via a user field are still notified. See Notifications.
See also: record_update(), record_get()