FM.InsertOrUpdateRecord
-----------------------

Inserts or updates a record in a table in one line.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) [FMSQL](component_FMSQL.md) | [6.0](newinversion60.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "FM.InsertOrUpdateRecord"; FileName; TableName; IDField; IDValue; FieldName...; FieldValue... ) 

**MBS**( **"FM.InsertOrUpdateRecord";** /\* Inserts or updates a record in a table in one line. \*/  
**$FileName**; /\* The file name of where the table is inside. Can be empty to look for the table in all files.e.g. 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.e.g. "Assets" \*/   
**$IDField**; /\* The name of the field which provides an unique ID for each record, so we can identify the field.  
Can be ID of field, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove table name automatically.e.g. "ID" \*/   
**$IDValue**; /\* The value for the ID field to identify the record.  
Data type of parameter must match the data type of the field.e.g. $RecordID \*/   
**$FieldName...**; /\* A field name to set.  
Can be ID of field, so we lookup name by ID.   
Can be result of GetFieldName() function as we remove table name automatically.e.g. "Model" \*/   
**$FieldValue...**) /\* A field value to use for setting the field in the parameter before.  
Data type of parameter must match the data type of the field.e.g. "Test" \*/ 

### 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. | 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" |
| IDField | The name of the field which provides an unique ID for each record, so we can identify the field.   Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "ID" |
| IDValue | The value for the ID field to identify the record.   Data type of parameter must match the data type of the field. | $RecordID |
| FieldName... | A field name to set.   Can be ID of field, so we lookup name by ID.    Can be result of GetFieldName() function as we remove table name automatically. | "Model" |
| FieldValue... | A field value to use for setting the field in the parameter before.   Data type of parameter must match the data type of the field. | "Test" |

### Result

Returns OK or error.

### Description

Inserts or updates a record in a table in one line.  
If the insert fails due to duplicate ID, we will update the record values.  
You pass to this function table name (and optional filename).  
To identify the record you pass the name of the ID field and the value for the record. The ID field must be unique.  
Then you pass one pair of field name and value for each field you like to set in the new record.  
  
This function combines [FM.InsertRecord](FMInsertRecord.md) and [FM.UpdateRecord](FMUpdateRecord.md). If the ID is already used, we update, else we insert a new record.  
  
For one ID field, please use FM.InsertOrUpdateRecord, for two ID fields [FM.InsertOrUpdateRecord2](FMInsertOrUpdateRecord2.md) and for three ID fields [FM.InsertOrUpdateRecord3](FMInsertOrUpdateRecord3.md).  
  
This function is broken in version 6.4 as it returns always a SQL error for insert. Please use 6.5 or newer.  
With plugin version 7.2 or later, 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.  
  
With plugin version 8.4 or newer, you can use GetFieldName() function to query field names and the plugin removes the table prefix with :: in the field name before passing it to SQL engine.  
  
You can use [FM.ExecuteSQL.LastSQL](FMExecuteSQLLastSQL.md) function to see later what SQL was created and run.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat FieldName and FieldValue parameters as often as you need.  
### Examples

Update a record:

 MBS ( "FM.InsertOrUpdateRecord";   
""; "Asset Management"; /\* file and table name \*/  
"Asset ID"; "1"; /\* ID field and value \*/  
"Information"; "Just a test"; /\* first field and value \*/  
"Category"; "BestItems" ) /\* second field and value \*/  
Insert or update record with 1 key field and 4 fields:

 MBS ("FM.InsertOrUpdateRecord"; $fileName ; $tableName ;   
$field1 ; $value1 ; // &lt;- primary key field name and value  
$field2 ; $value2 ; $field3 ; $value3 ; $field4 ; $value4 ; $field5 ; $value5 )  
Set a field with red bold text:

 MBS ( "FM.InsertOrUpdateRecord";   
Get(FileName); "Contacts";   
"ID"; Contacts::ID ;   
"First"; TextStyleAdd ( TextColor ( "Hello" ; RGB ( 255 ; 0 ; 0 ) ); bold ) )  
### See also

- [FM.ExecuteSQL](FMExecuteSQL.md)
- [FM.ExecuteSQL.LastSQL](FMExecuteSQLLastSQL.md)
- [FM.InsertOrUpdateRecord3](FMInsertOrUpdateRecord3.md)
- [FM.InsertOrUpdateRecord4](FMInsertOrUpdateRecord4.md)
- [FM.InsertOrUpdateRecord5](FMInsertOrUpdateRecord5.md)
- [FM.InsertOrUpdateRecordQuery](FMInsertOrUpdateRecordQuery.md)
- [FM.SQL.InsertOrUpdateRecords](FMSQLInsertOrUpdateRecords.md)
- [FM.UpdateRecord](FMUpdateRecord.md)
- [Matrix.InsertOrUpdateRecords](MatrixInsertOrUpdateRecords.md)
- [SQL.InsertOrUpdateRecords](SQLInsertOrUpdateRecords.md)

### Release notes

- **Version 16.1**
    - Rewrote [FM.InsertOrUpdateRecordQuery](https://www.mbsplugins.eu/FMInsertOrUpdateRecordQuery.shtml) to use newer code base.
- **Version 16.0**
    - Fixed an issue with [FM.InsertOrUpdateRecord](https://www.mbsplugins.eu/FMInsertOrUpdateRecord.shtml) and field names containing double colon.
- **Version 11.2**
    - Added [FM.InsertOrUpdateRecord4](https://www.mbsplugins.eu/FMInsertOrUpdateRecord4.shtml) and [FM.InsertOrUpdateRecord5](https://www.mbsplugins.eu/FMInsertOrUpdateRecord5.shtml).
- **Version 10.1**
    - Changed [FM.InsertRecord](https://www.mbsplugins.eu/FMInsertRecord.shtml), [FM.CompareTables](https://www.mbsplugins.eu/FMCompareTables.shtml), [FM.DeleteRecord](https://www.mbsplugins.eu/FMDeleteRecord.shtml), [FM.DeleteRecords](https://www.mbsplugins.eu/FMDeleteRecords.shtml), [FM.InsertOrUpdateRecord](https://www.mbsplugins.eu/FMInsertOrUpdateRecord.shtml) and [FM.UpdateRecord](https://www.mbsplugins.eu/FMUpdateRecord.shtml) to take table name from first field name if table name is empty.
- **Version 8.5**
    - Added check to [FM.InsertOrUpdateRecord2](http://www.mbsplugins.eu/FMInsertOrUpdateRecord2.shtml) to detect duplicate fields passed.

### Blog Entries

- [MBS FileMaker Advent calendar - Door 24 - Insert or Update](https://www.mbsplugins.de/archive/2025-12-24/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.6pr3](https://www.mbsplugins.de/archive/2025-12-15/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Insert or update with JSON](https://www.mbsplugins.de/archive/2024-08-28/Insert_or_update_with_JSON/monkeybreadsoftware_blog_filemaker)
- [New in MBS FileMaker Plugin 11.2](https://www.mbsplugins.de/archive/2021-05-26/New_in_MBS_FileMaker_Plugin_11/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.1pr1](https://www.mbsplugins.de/archive/2020-01-30/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 6.0 for OS X/Windows](https://www.mbsplugins.de/archive/2016-01-28/MBS_FileMaker_Plugin_60_for_OS/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.5pr1](https://www.mbsplugins.de/archive/2015-12-09/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 6/2018, Seite 23 bis 24](https://filemaker-magazin.de/neuigkeit/4025-Appetithappen-FMM_201806)
- [Ausgabe 3/2018, Seite 35](https://filemaker-magazin.de/neuigkeit/3953-Appetithappen-FMM_201803)

This function is free to use.

Created 5th December 2015 , last changed 15th April 2023

  
[FM.InitMessageFilter](FMInitMessageFilter.md) - [FM.InsertOrUpdateRecord2](FMInsertOrUpdateRecord2.md)

[HTML Version](FMInsertOrUpdateRecord.shtml)