« Core Location Geocode… | Home | Improve your work liv… »

Automate login to FileMaker Admin Console in web viewer

Today a client asked how to automate login to the admin console when it is open in a web viewer within a FileMaker solution. You probably saw the video Automate web viewer already?

The login here is a bit more difficult as you need a couple of JavaScript calls to login, but here is a script that works for us:

Set Variable [ $JS ; Value: "
function SendEvent(o, name)
  // send event to JavaScript event listeners¶
  var evt = document.createEvent('Events');
  evt.initEvent(name, true, true);

// set user name¶
o = document.getElementById('inputUserName');
o.value = '" & Admin Console::Username & "';
SendEvent(o, 'input');
SendEvent(o, 'blur');

// set password¶
o = document.getElementById('inputPassword');
o.value = '" & Admin Console::Password & "';
SendEvent(o, 'input');
SendEvent(o, 'blur');

document.getElementById('LOGN_Butn_SignIn').click();" ]
Set Variable [ $r ; Value: MBS("WebView.RunJavaScript"; "web"; Substitute ( $JS; ¶; Char(10) )) ]

As you see we define an utility function in JavaScript to trigger an event programmatically. This is required as the login form has event listeners in JavaScript which validate the fields and we need those to enable the Sign In button for us. we do the following steps for each field. We query the field by its ID, set the focus, enter the text and trigger input event to have the JavaScript recognize the changes and then blur it to remove focus. Finally on the end we trigger a click on the login button.

Please note that for text in a formula FileMaker removes the line breaks, so for each comment we add a ¶ character to indicate we want a line break there. Also we do a replace all here to change line endings to unix line endings before we run it with the WebView.RunJavaScript function.

If you have questions, please don't hesitate to contact us. The example will be included with next plugin version. FileMaker Plugin
12 02 20 - 14:01

Start Chat