Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 12.0   12.1   12.2   12.3   12.4   12.5   13.0   13.1   13.2   13.3    Statistic    FMM    Blog  


Defines a SQL Evaluate function for JavaScript.

Component Version macOS Windows Linux Server iOS SDK
JavaScript 10.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "JS.AddFileMakerSQLFunction"; JSRef; Name )   More


Parameter Description Example
JSRef The JavaScript reference number. $js
Name The name of the function. "test"


Returns OK or error.


Defines a SQL Evaluate function for JavaScript.
The function will take string parameter with file name and SQL and evaluate the result in FileMaker. Result is returned as text to JavaScript. You can pass additional parameters for filling parameters in SQL.

For increased security we prefer all FileMaker developers define their own function name, so if you get some foreign JavaScript, it can't know the function name and mess with FileMaker. Be aware that users may run commands like DELETE to delete all records of a table!


Run SQL from JavaScript:

Set Variable [ $js ; Value: MBS( "JS.New" ) ]
Set Variable [ $r ; Value: MBS( "JS.AddFileMakerSQLFunction"; $js; "FMSQL") ]
Show Custom Dialog [ "Result" ; MBS( "JS.Evaluate"; $JS; " \"got SQL result: \" + FMSQL(\"JavaScript.fmp12\", \"SELECT COUNT(*) FROM JavaScript\")" ) ]
Set Variable [ $r ; Value: MBS( "JS.Release"; $JS ) ]

Create JavaScript environment with SQL function to query FileMaker tables:

Set Variable [ $$JS ; Value: MBS("JS.New") ]
Set Variable [ $r ; Value: MBS( "JS.AddFileMakerSQLFunction"; $$js; "FMSQL") ]

See also

Example Databases

Blog Entries

This function checks for a paid license.

Created 7th December 2019, last changed 13th June 2021

JS.AddFileMakerRunScriptFunction - JS.AddFunction

💬 Ask a question or report a problem

Start Chat