« MBS FileMaker Plugin,… | Home | Iterating character s… »

Transitioning scripts for WebView2

If you have existing scripts to use our WebView functions in MBS FileMaker Plugin and you like to move to using FileMaker 19.3 on Windows, you may notice that the functions stop working. As of today we have no way to access the relevant C++ classes for the WebView2 control.

But if you urgently need to use one of our WebView functions, consider to change your scripts and use our plugin based web viewer. With the WebView.CreateWithControl function you can create an IE based web viewer on a layout and use our existing functions to do all the web viewer related functions:

#create with control on window
Set Variable [ $$web; Value:MBS("WebView.CreateWithControl"; 0; "placeholder"; 1) ]
Set Variable [ $r; Value:MBS( "WebView.LoadURL"; $$web; "http://www.mbs-plugins.com") ]

Since FileMaker 19 introduced the "Perform JavaScript in Web Viewer" script step. You may use that where needed to replace a few of our functions. But since it just allowed to call JavaScript functions, you may need to be able to control the html and include the requite functions.

Let's give you an example and change the TinyMCE example from us. We use here the WebView.SetFormTextAreaValue and WebView.RunJavaScript functions to pass text to the control. The form field is used to work around some limitations in the past on how much you can pass via URL or JavaScript calls. It still works well today:

Set Variable [ $r ; Value: MBS( "WebView.SetFormTextAreaValue" ; "HTMLEditor"; "formtest"; "output"; $text; 0 ) ]
Set Variable [ $r ; Value: MBS( "WebView.RunJavaScript" ; "HTMLEditor"; "try { tinyMCE.get('elm1').setContent(formtest.output.value); } catch (e) { alert(e); }" ) ]

Now to get this working with the script step, we have to define a JavaScript function to take the call. So we transform our JavaScript code above into a nice function called SetText and taking a single parameter named text:
function SetText(text)
  catch (e)
As you see we include some exception handling, which may tell you if something is not working. Now we call it with the script step and pass our $text variable:

Perform JavaScript in Web Viewer [ Object Name: "HTMLEditor" ; Function Name: "SetText" ; Parameters: $text ]

When you try this, you will notice it works just as fine as the existing calls with MBS FileMaker Plugin.
08 07 21 - 08:16