Skip links

Individual data exports with the Base Elements plugin.

File selection for data export from FileMaker

FileMaker Quick TipWith the "Export records" function, FileMaker has the following features Script-editor has a very powerful function to extract data from a FileMakerDatabase in various formats. However, if a data export is to be exported as a text file, for example as a CSV, FileMaker's on-board tools can sometimes reach their limits. On the one hand, FileMaker only supports the export of text files whose field contents are separated by a tab or a comma. By default, FileMaker also exports text files in UTF-16 format, which can often cause problems when importing on the other side, as most systems require UTF-8 as the format. If you compile the file to be created in FileMaker yourself, e.g. with a formula, there are often problems with the end of the line, as FileMaker does not insert a real line break. All these difficulties can be easily avoided by programming the data export yourself using the Base Elements plugin. In this article, we show you how easy it is to do this.

FileMaker Training and Coaching
Display

File selection and export with the Base Elements plugin

With the help of the Base Elements plugin, the entire export process from FileMaker including file selection can be implemented in a simple way. To display a dialog for saving a new file, add the following command to your script:

Set variable [$file; Value: BE_SaveFileDialog ("Title"; "FileDefault.csv"; "FilePathDefault")]

As with the export function integrated in FileMaker, the user can now navigate through their file system and create a new file at any point. If the selected file already exists, the operating system will ask whether the existing file should be replaced. The file name and path can be found after selecting or specifying the file name in the Variable $file and can be used in the following script steps. If the user has clicked on the [Cancel] is clicked, the variable $file blank.

File selection for data export from FileMaker

In the next step, the field names can now be written to the file to be exported if required. This is done using the Base Elements plugin with the following command:

Set variable [$error; Value: BE_WriteTextToFile ( $file; "bez1;bez2;bez3 ... ¶" )]

It is important at this point to insert the line break at the end of the field names. The individual data records can now be written to the file. As the export is fully scripted, writing takes place within a loop record by record.

Go to data/query/page [First(s)]
Loop (start)
Set variable [$error; Value: BE_WriteTextToFile ( $file; Field1 & ";" & Field2 & ";" ... & "¶"; 1 )]
Go to data/query/page [Next(r); End after last]
Loop (end)

In our example, we have used the semicolon as a field separator between the fields. Of course, you can also use any other field separator at this point. The line break at the end of the line and the additional parameter "1" of the "BE_WriteTextToFile" command are also important here. This parameter is called "append" and ensures that the line is added to the existing file and that the existing file is not overwritten by the line. By default, the text file is exported in UTF-8 format. The following other character encodings can also be used with the "BE_SetTextEncoding" command:

Supported character encodings

ASCII, ISO-8859-{1, 2, 3, 4, 5, 7, 9, 10, 13, 14, 15, 16}, KOI8-R, KOI8-U, KOI8-RU, CP{1250, 1251, 1252, 1253, 1254, 1257}, CP{850, 866, 1131}, Mac{Roman, CentralEurope, Iceland, Croatian, Romania}, Mac{Cyrillic, Ukraine, Greek, Turkish}, Macintosh, ISO-8859-{6,8}, CP{1255,1256}, CP862, Mac{Hebrew,Arabic}, EUC-JP, SHIFT_JIS, CP932, ISO-2022-JP, ISO-2022-JP-2, ISO-2022-JP-1, EUC-CN, HZ, GBK, CP936, GB18030, EUC-TW, BIG5, CP950, BIG5-HKSCS, BIG5-HKSCS:2004, BIG5-HKSCS:2001, BIG5-HKSCS:1999, ISO-2022-CN, ISO-2022-CN-EXT, EUC-KR, CP949, ISO-2022-KR, JOHAB, ARMSCII-8, Georgian-Academy, Georgian-PS, KOI8-T, PT154, RK1048, ISO-8859-11, TIS-620, CP874, MacThai, MuleLao-1, CP1133, VISCII, TCVN, CP1258, HP-ROMAN8, NEXTSTEP, UTF-8, UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UTF-16, UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF-7, C99, JAVA, UCS-2-INTERNAL, UCS-4-INTERNAL, CP {437, 737, 775, 852, 853, 855, 857, 858, 860, 861, 863, 865, 869, 1125}, CP864, EUC-JISX0213, Shift_JISX0213, ISO-2022-JP-3, BIG5-2003, TDS565, ATARIST and RISCOS-LATIN1

Base Elements Plugin is free of charge

The Base Elements plugin is available free of charge and is available for Mac OS X and Windows in both 32-bit and 64-bit versions. Download is available. The plugin now has a wide range of commands in the following areas:

  • Vector editing
  • Clipboard
  • Constants
  • Container fields
  • Dialogs
  • Encoding and decoding (Base64, AES)
  • Error handling
  • File and directory functions
  • HTTP and URL functions
  • Script functions (JavaScript, FileMaker scripts)
  • SMTP e-mail
  • Time functions
  • Value lists
  • XML, XSLT and JSON
  • ZIP and GZIP

All functions are displayed on the Wiki page of the plugin documented in detail.

Reach your goal faster with FileMaker coaching and training

Did you know that goFileMaker.de also offers FileMaker Coaching and Training offers? We are happy to assist you nationwide via remote maintenance with the development or expansion of your FileMaker solution. Please contact us if you are interested!

Leave a comment

  1. This article shows the principle of how text files can be exported in any conceivable form using the Base Elements plugin. However, the export shown is not 100% perfect, because a line break ("¶") is generated after each line in the manner described above, i.e. also in the last line. Of course, this can also be prevented by using the "Set variable" command within the loop

    & "¶" is replaced by

    & If(Get(RecordItemInResultSet) < Get(NumberOfRecordsFound); "¶"; "")

Share this page:

ERP software as flexible as your company.
We will be happy to advise you.

Customizable ERP software for Mac, Windows and iOS.

You are here: Exporting data from FileMaker as an individual text file