| Components | All | New | MacOS | Windows | Linux | iOS | ||||
| Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old | |
Plugin.RegisterFunction
Registers a custom function with FileMaker or JavaScript code.
| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
| Plugin | 15.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "Plugin.RegisterFunction"; functionId; Name; Prototype; Expression { ; MinParameter; MaxParameter; Flags } ) More
Parameters
| Parameter | Description | Example | Flags |
|---|---|---|---|
| functionId | The function ID. Must be unique and 3 or higher. MBS function is ID 1 and MBS script step is ID 2. |
123 | |
| Name | The name of the custom function. | "Concat" | |
| Prototype | The prototype to show in the user interface. Defines the names of parameters. |
"Concat(a, b)" | |
| Expression | The expression to run. | "a+b" | |
| MinParameter | The minimum parameter count. | 0 | Optional |
| MaxParameter | The maximum parameter count. Pass -1 for unlimited parameters. |
2 | Optional |
| Flags | The flags for the function. | 0 | Optional Added in version 15.4. |
Result
Returns OK or error.
Description
Registers a custom function with FileMaker or JavaScript code.Allows you to define custom functions for your solution, which are accessible from all files.
Please register the same function each time your solution opens with the same IDs. FileMaker usually finds functions by ID, but with Evaluate() it matches them by name.
If you take variable number of arguments, you need to use Plugin.CustomFunctionParameter function.
| Flag | Description |
|---|---|
| 0 | Evaluate with FileMaker |
| 1 | Use Duktape JavaScript engine |
| 2 | Use WebKit JavaScript engine if available (see JavaScript.Available) or fall back to Duktape. |
| 4 | Add 4 to use a per thread JavaScript context, so globals are shared within the scripts running on tha thread. in FileMaker Pro you only have one thread, but on server, you may have multiple threads. |
| 8 | Add 8 to secure the function and prevent it from being unregistered or replaced. |
If you use JavaScript, you should declare a function in JavaScript to take the right number of parameters. Your function should return a result as text, boolean or number. If you have objects or arrays, please use JSON.stringify function to serialize them to text. Your JavaScript can define additional things you use in your function.
Examples
Register custom function:
# Register one function. Replacing older one with same id
Set Variable [ $r ; Value: MBS("Plugin.RegisterFunction";
123; // ID to use
"Concat"
"Concat(Value1; Value2)";
"Value1 & Value2";
2; // min and max parameters
2) ]
If [ MBS("IsError") ]
Show Custom Dialog [ "Failed to add function." ; $r ]
End If
Set Variable [ $r ; Value: MBS("Plugin.RegisterFunction";
123; // ID to use
"Concat"
"Concat(Value1; Value2)";
"Value1 & Value2";
2; // min and max parameters
2) ]
If [ MBS("IsError") ]
Show Custom Dialog [ "Failed to add function." ; $r ]
End If
Register a function with JavaScript:
MBS("Plugin.RegisterFunction"; 7; "ConcatJS"; "ConcatJS(Value1; Value2)"; "function ConcatJS(a, b) {
return String(a) + String(b);
}"; 2; 2; 1)
return String(a) + String(b);
}"; 2; 2; 1)
Register a new counter function using WebKit with globals:
MBS( "Plugin.RegisterFunction"; 11; "TestCounterWK()"; "function TestCounterWK() {
globalThis.counter = (globalThis.counter || 0) + 1;
return globalThis.counter;
}"; 0; 0; 2 + 4)
globalThis.counter = (globalThis.counter || 0) + 1;
return globalThis.counter;
}"; 0; 0; 2 + 4)
See also
- IsError
- JavaScript.Available
- Plugin.CustomFunctionParameter
- Plugin.RegisterScriptStep
- Plugin.UnregisterFunction
Release notes
- Version 15.5
- Added flag 8 for Plugin.RegisterFunction function to secure a function and prevent unregister or replacement.
- Fixed Plugin.RegisterFunction to handle optional parameters better and create temporary variables for the calculations.
- Version 15.4
- Added flags for Plugin.RegisterFunctionand Plugin.RegisterScriptStep functions, so you can turn on JavaScript.
- Improved custom functions with Plugin.RegisterFunction to handle optional parameters better. Use {} in the parameters to declare optional ones.
- Improved custom functions with Plugin.RegisterFunction to properly pass through errors, so Get(LastError) can see it.
- Version 15.3
- Added Plugin.RegisterFunction function to register custom functions on the fly. These show up in calculation dialogs just like regular custom functions.
- Improved Plugin.RegisterFunction to pass parameters as they appear in prototype.
Example Databases
Blog Entries
- MBS FileMaker Plugin, version 15.5pr3
- MBS FileMaker Plugin, version 15.5pr2
- MBS FileMaker Plugin, version 15.5pr1
- MBS Plugin 15.4 for Claris FileMaker
- Register custom functions with MBS Plugin
- MBS FileMaker Plugin, version 15.4pr4
- MBS FileMaker Plugin, version 15.4pr1
- MBS FileMaker Plugin 15.3 News
- MBS Plugin 15.3 for Claris FileMaker
- MBS FileMaker Plugin, version 15.3pr6
This function checks for a license.
Created 26th June 2025, last changed 2nd October 2025