« Read patient name fro… | Home | Send text message fro… »

Login in FileMaker web viewer if needed

Sometimes you may want to show a website in a webviewer, but a login is required. We solved this for a client today with the following script. First we go by script to the website. If we have to login, there is a login form, so we set the user name and password. If the field is not found, we are logged in and exit the script. Otherwise we click the login button and continue to the final website:

 

 # Load website

Set Web Viewer [ Object Name: "web" ; URL: "https://somedomain/search" ] 

# Wait for it

Loop

Pause/Resume Script [ Duration (seconds): ,1 ] 

Exit Loop If [ MBS("webview.isloading"; "web") ≠ 1 ] 

End Loop

# Set login name

Set Variable [ $r ; Value: MBS( "WebView.SetFormInputValue"; "web"; "login_form"; "__ac_name"; "xxx") ] 

If [ MBS("iserror") ] 

# No form, so we are already logged in?

If [ Position ( $r ; "failed to find form" ; 1 ; 1 ) = 0 ] 

Show Custom Dialog [ "Failed to set username field." ; $r ] 

End If

Exit Script [ Text Result:    ] 

End If

# Set password

Set Variable [ $r ; Value: MBS( "WebView.SetFormInputValue"; "web"; "login_form"; "__ac_password"; "xxx") ] 

If [ MBS("iserror") ] 

Show Custom Dialog [ "Failed to set password field." ; $r ] 

End If

# Wait

Pause/Resume Script [ Duration (seconds): ,1 ] 

# Click login button

Set Variable [ $r ; Value: MBS( "WebView.ClickInput"; "web"; "login_form"; "submit") ] 

If [ MBS("iserror") ] 

Show Custom Dialog [ "Failed to click submit button." ; $r ] 

End If

# or submit form

// Set Variable [ $r ; Value: MBS( "WebView.formsubmit"; "web"; "login_form") ] 

// If [ MBS("iserror") ] 

// Show Custom Dialog [ "Fehler" ; $r ] 

// End If

# Wait for page loading after login

Loop

Pause/Resume Script [ Duration (seconds): ,1 ] 

Exit Loop If [ MBS("webview.isloading"; "web") ≠ 1 ] 

End Loop

# Go to search page where we want to be after login

Set Web Viewer [ Object Name: "web" ; URL: "https://somedomain/search" ] 

Next user can do a search and find information to use in the FileMaker solution. If needed, our plugin can assist to extract text or html live content from the web viewer as well as query content of certain DOM elements via JavaScript (see WebView.RunJavaScript) . In case the website changes layout, you may need to adjust the script with new form and field names.

Claris FileMaker Plugin
08 03 19 - 20:51