« MBS Plugin Advent cal… | Home | JSON Search Example »

Use Perform Script on Server inside Data API script

We recently had a client with a problem exporting data in a server side script. Since server scripts run blindly and we can't debug them, we check FileMaker's logs, enable script error logging and add calls for MBS("Trace") and MBS("Log"; ...) calls to log data to the log file from our MBS FileMaker Plugin.

We quickly noticed that the Export Records script step failed with error 3, which is command unavailable. After that I quickly looked though FileMaker's documentation and identified functions with limited Data API support:

FunctionData APIServer
Close Data FileNoYes
Configure Machine Learning ModelNoPartial
Copy All Records/RequestsNoYes
Copy Record/RequestNoYes
Create Data FileNoYes
Exit ApplicationNoYes
Export RecordsNoPartial
Get Data File PositionNoYes
Get File ExistsNoYes
Get File SizeNoYes
Import RecordsNoPartial
OnFirstWindowOpenNoYes
OnLastWindowClosePartialYes
Open Data FileNoYes
Print SetupNoPartial
Read from Data FileNoYes
Save Records as PDFYesPartial
Set Data File PositionNoYes
Show/Hide ToolbarsNoYes
Write to Data FileNoYes

As you see, there are plenty of functions, which are not supported for Data API, but are for normal server scripting. This table is based on Claris FileMaker 20.3 documentation, so it may be different for your version of FileMaker Server.

If you like to use a function like Export Records in your script, you may need to use Perform Script on Server to run the script in the server scripting process.

For our client, it looks like this:

They use FM Better Forms, where the user clicks a button. This button then performs the script in Data API engine. Since Export Records script step is not available, we have to trigger another script using Perform Script on Server. This script then goes to the right layout and record ID (passed as script parameter). Then the script does the Export script step and signals back the result.

Over time we hope Claris can support more script steps for Data API as the code should be there. MBS FileMaker Plugin can be used on all three engines on FileMaker Server: Server Scripting, Data API and Web Direct.

Claris FileMaker Plugin
11 12 23 - 12:05