JS.AddFileMakerSQLFunction
--------------------------

Defines a SQL Evaluate function for JavaScript.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JavaScript](component_JavaScript.md) | [10.0](newinversion100.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JS.AddFileMakerSQLFunction"; JSRef; Name ) 

**MBS**( **"JS.AddFileMakerSQLFunction";** /\* Defines a SQL Evaluate function for JavaScript. \*/  
**$JSRef**; /\* The JavaScript reference number.e.g. $js \*/   
**$Name**) /\* The name of the function.e.g. "test" \*/ 

### Parameters

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

### Result

Returns OK or error.

### Description

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!  
### Examples

Run SQL from JavaScript:

 Set Variable \[ $js ; Value: MBS ( "[JS.New](JSNew.md)" ) \]   
Set Variable \[ $r ; Value: MBS ( "JS.AddFileMakerSQLFunction"; $js ; "FMSQL") \]   
Show Custom Dialog \[ "Result" ; MBS ( "[JS.Evaluate](JSEvaluate.md)"; $JS ; " \\"got SQL result: \\" + FMSQL(\\"JavaScript.fmp12\\", \\"SELECT COUNT(\*) FROM JavaScript\\")" ) \]   
Set Variable \[ $r ; Value: MBS ( "[JS.Release](JSRelease.md)"; $JS ) \]  
Create JavaScript environment with SQL function to query FileMaker tables:

 Set Variable \[ $$JS ; Value: MBS ("[JS.New](JSNew.md)") \]   
Set Variable \[ $r ; Value: MBS ( "JS.AddFileMakerSQLFunction"; $$js ; "FMSQL") \]  
### See also

- [JS.CF](JSCF.md)
- [JS.Evaluate](JSEvaluate.md)
- [JS.New](JSNew.md)
- [JS.Release](JSRelease.md)

### Example Databases

- [JavaScript/JavaScript](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript.shtml#8ScriptAnchor_)

### Blog Entries

- [Custom Functions in JavaScript](https://www.mbsplugins.de/archive/2021-06-14/Custom_Functions_in_JavaScript/monkeybreadsoftware_blog_filemaker)
- [Our JavaScript engine for FileMaker](https://www.mbsplugins.de/archive/2019-12-09/Our_JavaScript_engine_for_File/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[JS.AddFileMakerRunScriptFunction](JSAddFileMakerRunScriptFunction.md) - [JS.AddFunction](JSAddFunction.md)

[HTML Version](JSAddFileMakerSQLFunction.shtml)