JS.CallFunction
---------------

Calls a global function given the name with JSON data.

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

MBS( "JS.CallFunction"; JSRef; Name { ; Parameters... } ) 

**MBS**( **"JS.CallFunction";** /\* Calls a global function given the name with JSON data. \*/  
**$JSRef**; /\* The JavaScript reference number.e.g. $js \*/   
**$Name**; /\* The name of the function.e.g. "test" \*/   
**$Parameters...**) /\* Optional; JSON to pass as parameter. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| JSRef | The JavaScript reference number. | $js |  |
| Name | The name of the function. | "test" |  |
| Parameters... | JSON to pass as parameter. |  | Optional |

### Result

Returns JSON or error.

### Description

Calls a global function given the name with JSON data.  
Parameters are passed to the function. Please pass as many parameters in FileMaker as needed.  
If the function needs more parameter, undefined values are used to fill up.  
If the function needs less parameters, additional ones are dropped.  
Returns the result of the function converted to a JSON value.   
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Parameters parameter as often as you need.  
### Examples

Define a function and call it:

 Set Variable \[ $js ; Value: MBS ( "[JS.New](JSNew.md)" ) \]   
Set Variable \[ $r ; Value: MBS ( "[JS.AddFunction](JSAddFunction.md)"; $js ; "adder"; "function (x,y) { return x+y; }" ) \]   
Show Custom Dialog \[ "Result" ; MBS ( "JS.CallFunction"; $JS ; "adder"; 3; 4 ) \]   
Set Variable \[ $r ; Value: MBS ( "[JS.Release](JSRelease.md)"; $JS ) \]  
Concat strings:

 Set Variable \[ $js ; Value: MBS ( "[JS.New](JSNew.md)" ) \]   
Set Variable \[ $r ; Value: MBS ( "[JS.AddFunction](JSAddFunction.md)"; $js ; "Concat"; "function (x,y) { return x+\\" \\"+y; }" ) \]   
Show Custom Dialog \[ "Result" ; MBS ( "JS.CallFunction"; $JS ; "Concat"; "\\"Hello\\""; "\\"World\\"" ) \]   
Set Variable \[ $r ; Value: MBS ( "[JS.Release](JSRelease.md)"; $JS ) \]  
Call a function:

 If \[ Length($$js ) &gt; 0 \]   
 Set Variable \[ $p ; Value: MBS ( "[JSON.CreateString](JSONCreateString.md)"; test::Input ) \]   
 Set Field \[ test::Output ; MBS ( "JS.CallFunction"; $$js ; "crc32"; $p ) \]   
End If  
### See also

- [JS.AddFunction](JSAddFunction.md)
- [JS.CallFunctionValues](JSCallFunctionValues.md)
- [JS.CF](JSCF.md)
- [JS.New](JSNew.md)
- [JS.Release](JSRelease.md)
- [JSON.CreateString](JSONCreateString.md)

### Release notes

- **Version 11.3**
    - Added [JS.List](https://www.mbsplugins.eu/JSList.shtml) and [JS.CallFunctionValues](https://www.mbsplugins.eu/JSCallFunctionValues.shtml) function.
    - Changed [JS.CallFunction](https://www.mbsplugins.eu/JSCallFunction.shtml) and [JS.SetGlobalProperty](https://www.mbsplugins.eu/JSSetGlobalProperty.shtml) to not return an error for invalid JSON, but just take it as text for your convenience.

### Example Databases

- [JavaScript/CoordinatDistance](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/CoordinatDistance.shtml#1ScriptAnchor_)
- [JavaScript/FM JSON Path](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/FM%20JSON%20Path.shtml#1ScriptAnchor_)
- [JavaScript/JavaScript Custom Functions](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript%20Custom%20Functions.shtml#4ScriptAnchor_)
- [JavaScript/JavaScript](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript.shtml#3ScriptAnchor_)

### Blog Entries

- [Custom Functions in JavaScript](https://www.mbsplugins.de/archive/2021-06-14/Custom_Functions_in_JavaScript/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.3pr2](https://www.mbsplugins.de/archive/2021-06-09/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [FileMaker and JavaScript - the perfect combination](https://www.mbsplugins.de/archive/2020-02-03/FileMaker_and_JavaScript_-_the/monkeybreadsoftware_blog_filemaker)
- [New in the MBS FileMaker Plugin 10.0](https://www.mbsplugins.de/archive/2020-01-23/New_in_the_MBS_FileMaker_Plugi/monkeybreadsoftware_blog_filemaker)
- [CRC function in FileMaker using JavaScript](https://www.mbsplugins.de/archive/2020-01-15/CRC_function_in_FileMaker_usin/monkeybreadsoftware_blog_filemaker)
- [Our JavaScript engine for FileMaker](https://www.mbsplugins.de/archive/2019-12-09/Our_JavaScript_engine_for_File/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 4/2021, Seite 21](https://filemaker-magazin.de/neuigkeit/4152-Appetithappen-FMM_202104)

This function checks for a license.

Created 7th December 2019 , last changed 14th July 2022

  
[JS.CF](JSCF.md) - [JS.CallFunctionValues](JSCallFunctionValues.md)

[HTML Version](JSCallFunction.shtml)