« Upload email to Sent … | Home | Spotlight search in F… »

Trigger FileMaker Scripts from JavaScript in FileMaker 16

As you may know FileMaker 16 on macOS uses WebKit 2.x, so our old WebView.InstallCallback function broke. We got a workaround using WebView.Create for creating WebKit 1.x web viewers in FileMaker 16 and using older WebKit functions.

Now we have a new way for WebKit 2.x using a JavaScript bridging. With macOS 10.10 (and iOS 8.0) Apple introduced the ability to install custom JavaScript message handlers for WKWebView. We just added them for our plugins to call back from JavaScript to FileMaker scripts.
First you call Webview.AddScriptMessageHandler function to register a name:

MBS( "Webview.AddScriptMessageHandler"; Name )

Next you can use it in Javascript to trigger a script in FileMaker from JavaScript:

window.webkit.messageHandlers.test.postMessage({'filename':'WebView Message Handler.fmp12', 'parameter':'Hello World from JavaScript', 'scriptName':'test'});

And you can evaluate an expression in JavaScript:

window.webkit.messageHandlers.test.postMessage({'evaluate':'MBS( "Msgbox"; "Hello from Evaluate in JavaScript" )'});

As you see, we get for our message handler a new entry in the namespace called window.webkit.messageHandlers.test. This allows us to call postMessage method there and this triggers the plugin code to trigger scripts or do evaluation. The parameter to the postMessage must be a Javascript object with a few properties:
  • fileName: The name of the file with the script.
  • scriptName: The name of the script to trigger.
  • parameter: The parameter to pass to the script.
  • evaluate: The expression to evaluation.
This works nice in first tests and we'd love to see what you can do with this technique. Please try with next prerelease or email us for a copy today.

PS: Works in FileMaker 16 runtimes, too. Claris FileMaker Plugin
15 12 17 - 13:59