Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
JS.CallFunction
Calls a global function given the name with JSON data.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
JavaScript | 10.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
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" ) ]
Set Variable [ $r ; Value: MBS( "JS.AddFunction"; $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"; $JS ) ]
Concat strings:
Set Variable [ $js ; Value: MBS( "JS.New" ) ]
Set Variable [ $r ; Value: MBS( "JS.AddFunction"; $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"; $JS ) ]
Call a function:
If [ Length($$js) > 0 ]
Set Variable [ $p ; Value: MBS( "JSON.CreateString"; test::Input) ]
Set Field [ test::Output ; MBS( "JS.CallFunction"; $$js; "crc32"; $p ) ]
End If
See also
Release notes
- Version 11.3
- Added JS.List and JS.CallFunctionValues function.
- Changed JS.CallFunction and JS.SetGlobalProperty to not return an error for invalid JSON, but just take it as text for your convenience.
Example Databases
- JavaScript/CoordinatDistance
- JavaScript/FM JSON Path
- JavaScript/JavaScript Custom Functions
- JavaScript/JavaScript
Blog Entries
- Custom Functions in JavaScript
- MBS FileMaker Plugin, version 11.3pr2
- FileMaker and JavaScript - the perfect combination
- New in the MBS FileMaker Plugin 10.0
- CRC function in FileMaker using JavaScript
- Our JavaScript engine for FileMaker
FileMaker Magazin
This function checks for a license.
Created 7th December 2019, last changed 14th July 2022