Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

JSON.InsertRecord

Inserts a new record in a table in one line using JSON.

Component Version macOS Windows Linux Server iOS SDK
JSON 14.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "JSON.InsertRecord"; FileName; TableName; JSON )   More

Parameters

Parameter Description Example
FileName The file name of where the table is inside. Can be empty to look for the table in all files.

Using a table in another database file may require you adding the other file as an external data source and adding the external table to your relationship graph to grant access.
Get(FileName)
TableName The name of the table to insert record into.
Can be ID of table, so we lookup name by ID.
Can be result of GetFieldName() function as we remove field name automatically.
"Assets"
JSON The JSON object with the record.

Result

Returns OK or error.

Description

Inserts a new record in a table in one line using JSON.
You pass to this function table name (and optional filename).
Then you pass a JSON with a field names and values for each field you like to set in the new record.

As we can't know the new ID assigned for the record, you can help yourself by passing in an UUID for a field and later select that to get the auto assigned primary key (or have the UUID be the primary key, so you don't need a query).

See also JSON.UpdateRecord to update a record.
You can specify fields and table via IDs and the plugin will lookup them for you at runtime. Table IDs and table names must be unique across all open files for this to work correctly.

You can use FM.ExecuteSQL.LastSQL function to see later what SQL was created and run.
The SQL functions in FileMaker do not trigger OnWindowsTransaction script trigger.

Does not take part in transactions in FileMaker. Changes are made directly to the database, so you can't revert them later with Revert Transaction script step.

We auto convert text values to date, time or timestamp if the plugin sees the fields having such a type. Otherwise the type of JSON value defines the data type. If JSON contains an array or object, we make text from it.

You can use FM.SQL.Execute function to query records in FileMaker and get them as JSON with FM.SQL.JSONRecords function. If needed, use JSON.ReplaceEvaluate or JSON.Replace to adjust the JSON and make modifications. Then use JSON.InsertRecord or JSON.InsertOrUpdateRecord to insert them.

Examples

Insert records with JSON:

MBS("JSON.InsertRecord"; ""; "Contacts"; "{\"FirstName\": \"John\", \"TheNumber\": 123}")

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 20th August 2024, last changed 4th September 2024


JSON.InsertOrUpdateRecord - JSON.InsertRecords