FM.InsertRecordCSV
------------------

Inserts records based on CSV text.

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

MBS( "FM.InsertRecordCSV"; InsertFileName; InsertTableName; FieldNames; Text { ; Delimiter; FieldName...; FieldValue... } ) 

**MBS**( **"FM.InsertRecordCSV";** /\* Inserts records based on CSV text. \*/  
**$InsertFileName**; /\* The file name of where the insert table is inside.   
Can be empty to look for the table in all files.e.g. Get(FileName) \*/   
**$InsertTableName**; /\* 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" \*/   
**$FieldNames**; /\* A list of field names for the insert.   
Empty entries in the list are ignored.  
  
If you like to skip a field, you may include a field name multiple time, so the first assignment will then be overwritten by the following assignment.e.g. "First¶Last¶Zip¶Work City" \*/   
**$Text**; /\* The text to import in TSV/CSV format.   
This means tab, comma or semicolon character between fields and newline character for new records.  
Use Files.ReadTextFile if needed to read this from a file on disk.e.g. "Bob;Miller;12345;New York" \*/   
**$Delimiter**; /\* Optional; The delimiter to use.  
If empty, we auto detect it.e.g. ";" \*/   
**$FieldName...**; /\* Optional; A field name to set.e.g. "Model" \*/   
**$FieldValue...**) /\* Optional; 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 | Flags |
|---|---|---|---|
| InsertFileName | The file name of where the insert table is inside.    Can be empty to look for the table in all files. | Get(FileName) |  |
| InsertTableName | 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" |  |
| FieldNames | A list of field names for the insert.    Empty entries in the list are ignored.      If you like to skip a field, you may include a field name multiple time, so the first assignment will then be overwritten by the following assignment. | "First¶Last¶Zip¶Work City" |  |
| Text | The text to import in TSV/CSV format.    This means tab, comma or semicolon character between fields and newline character for new records.   Use Files.ReadTextFile if needed to read this from a file on disk. | "Bob;Miller;12345;New York" |  |
| Delimiter | The delimiter to use.   If empty, we auto detect it. | ";" | Optional      Added in version **8.5**. |
| FieldName... | A field name to set. | "Model" | Optional |
| 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" | Optional |

### Result

Returns OK or error.

### Description

Inserts records based on CSV text.  
This function allows for easy importing of text to create a lot of records.  
Filename parameters can be empty.  
Use [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md) and [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md) to see error message.  
  
Reports an error if field name list doesn't match column count of the query result. Since version 8.2 we can fill text, number, time, timestamp and date fields and let FileMaker convert the values with your current locale.  
  
Returns number of records added.  
  
CSV is automatically parsed per line with [List.CSVSplit](ListCSVSplit.md) function internally.  
  
You can pass one pair of field name and value for each extra field you like to set in the new records. e.g. a reference ID.  
  
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.  
  
Version 8.5 adds Delimiter parameter, which may break scripts, but we need to have that parameter for people with older version.  
  
Version 11.1 does handle backslashes inside quotes for \\r and \\n for returns and \\t for tabs. You can use \\\\ for backslash.  
  
This function uses our field type cache from the [Audit](component_Audit.md) functions to determinate the type of a field. If you change a field type, you may restart FileMaker or use [Audit.ClearCaches](AuditClearCaches.md) to clear it.  
  
If input is stored in a container, you can use [Text.ReadTextFromContainer](TextReadTextFromContainer.md) function to read text first and pass it to this function.  
  
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

Import some contacts with passing import ID/timestamp:

 MBS ( "FM.InsertRecordCSV"; "Contacts.fmp12"; "Contacts"; "FirstName¶LastName¶City"; $tsv ; ""; "ImportID"; $importID ; "ImportDate"; Get(CurrentHostTimeStamp))  
Import CSV:

 MBS ( "FM.InsertRecordCSV"; "Kontakte.fmp12"; "Kontakte"; "Vorname¶Nachname¶Firma¶Position"; "Vorname;Nachname;Firma;Position")  
Import with escaped returns:

 MBS ( "FM.InsertRecordCSV"; "Contacts.fmp12"; "Contacts"; "First¶Last¶Work City"; """Christian\\rPeter"";Schmitz;""Nickenich\\nGermany""")  
### See also

- [Audit.ClearCaches](AuditClearCaches.md)
- [FM.ExecuteSQL](FMExecuteSQL.md)
- [FM.ExecuteSQL.LastError](FMExecuteSQLLastError.md)
- [FM.ExecuteSQL.LastErrorMessage](FMExecuteSQLLastErrorMessage.md)
- [FM.InsertRecord](FMInsertRecord.md)
- [FM.InsertRecordQuery](FMInsertRecordQuery.md)
- [FM.InsertRecordTSV](FMInsertRecordTSV.md)
- [List.CSVSplit](ListCSVSplit.md)
- [Text.ReadTextFromContainer](TextReadTextFromContainer.md)
- [XML.InsertRecords](XMLInsertRecords.md)

### Release notes

- **Version 14.5**
    - Improved type detection for [FM.InsertRecordCSV](https://www.mbsplugins.eu/FMInsertRecordCSV.shtml) function.
- **Version 11.2**
    - Changed [FM.InsertRecordCSV](https://www.mbsplugins.eu/FMInsertRecordCSV.shtml) and [FM.InsertRecordTSV](https://www.mbsplugins.eu/FMInsertRecordTSV.shtml) to recognize backslash escapes to have returns and tabs escaped in text.
- **Version 9.3**
    - Rewrote [FM.InsertRecordCSV](http://www.mbsplugins.eu/FMInsertRecordCSV.shtml) to support multi line values.
- **Version 9.2**
    - Fixed problem with delimiter detection in [FM.InsertRecordCSV](http://www.mbsplugins.eu/FMInsertRecordCSV.shtml).
- **Version 8.5**
    - Added delimiter parameter for [List.CSVSplit](http://www.mbsplugins.eu/ListCSVSplit.shtml), [QuickList.CSVSplit](http://www.mbsplugins.eu/QuickListCSVSplit.shtml) and [FM.InsertRecordCSV](http://www.mbsplugins.eu/FMInsertRecordCSV.shtml).
- **Version 8.2**
    - Improved [FM.InsertRecordCSV](http://www.mbsplugins.eu/FMInsertRecordCSV.shtml) and [FM.InsertRecordTSV](http://www.mbsplugins.eu/FMInsertRecordTSV.shtml) to handle date/time/timestamp fields.
- **Version 8.0**
    - Changed [FM.InsertRecordCSV](http://www.mbsplugins.eu/FMInsertRecordCSV.shtml) and [FM.InsertRecordTSV](http://www.mbsplugins.eu/FMInsertRecordTSV.shtml) to detect whether columns are numbers instead of text and handle it correctly.
- **Version 7.4**
    - Added CSV functions: [FM.InsertRecordCSV](http://www.mbsplugins.eu/FMInsertRecordCSV.shtml), [List.CSVSplit](http://www.mbsplugins.eu/ListCSVSplit.shtml) and [QuickList.CSVSplit](http://www.mbsplugins.eu/QuickListCSVSplit.shtml).

### Example Databases

- [JSON/JSON Insert and Update](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JSON/JSON%20Insert%20and%20Update.shtml#7ScriptAnchor_)
- [Text functions/CSV Import](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Text%20functions/CSV%20Import.shtml#1GroupButton48.0000000426.000000073.0000000547.0000000LayoutObjectAnchor_)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 19 - CSV and TSV](https://www.mbsplugins.de/archive/2025-12-19/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.5pr5](https://www.mbsplugins.de/archive/2024-10-28/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Find new records with RowID](https://www.mbsplugins.de/archive/2021-05-22/Find_new_records_with_RowID/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.2pr5](https://www.mbsplugins.de/archive/2021-05-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.3pr2](https://www.mbsplugins.de/archive/2019-06-12/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.2pr1](https://www.mbsplugins.de/archive/2019-04-02/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.5pr3](https://www.mbsplugins.de/archive/2018-10-24/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.2pr1](https://www.mbsplugins.de/archive/2018-04-04/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [CSV functions in MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-11-01/CSV_functions_in_MBS_FileMaker/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 7.4 - More than 4900 Functions In One Plugin](https://www.mbsplugins.de/archive/2017-09-26/MBS_FileMaker_Plugin_74_-_More/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2018, Seite 35](https://filemaker-magazin.de/neuigkeit/3953-Appetithappen-FMM_201803)

This function checks for a license.

Created 21st September 2017 , last changed 29th January 2023

  
[FM.InsertRecord](FMInsertRecord.md) - [FM.InsertRecordQuery](FMInsertRecordQuery.md)

[HTML Version](FMInsertRecordCSV.shtml)