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.

FlagDescription
0Evaluate with FileMaker
1Use Duktape JavaScript engine
2Use WebKit JavaScript engine if available (see JavaScript.Available) or fall back to Duktape.
4Add 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.
8Add 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

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)

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)

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 26th June 2025, last changed 2nd October 2025


Plugin.PrepareForUpdate - Plugin.RegisterScriptStep