With the release of FileMaker 19, it becomes easier than ever (it was already largely possible before – I had the opportunity to show the “#hash trick” in a few conferences 😉 ) to make FileMaker and Javascript communicate. Notably by executing Javascript code in a Web Viewer thanks to the script step Perform Javascript in Web Viewer (FileMaker asking the Web Viewer to execute a Javascript), and to the FileMaker.PerformScript Javascript class (“FileMaker script name”, “Optional parameter” ), Javascript calling a FileMaker script.
However, in our opinion, the latter lacks some possibilities. We have mentioned here the impossibility to resume a FileMaker script that would be paused, but there is also the absence of possibility to differentiate the called script (callback) according to success or failure. This article develops this last point and provides a solution.
Synchronous programming
No library is necessary, but I had to write my own class that extends a bit FileMaker.PerformScript to FileMaker.PerformScript ( scriptName, parameter, successCallback, errorCallback ).
A small example to make a bidirectional interaction between FileMaker and Web Viewer. It is a system of callback and/or promise, a way that Javascript often calls something from the outside and depending on whether everything went well (success) or badly (error), you let something happen in your Javascript application.
In fact, it all boils down to this: “FileMaker, call this script. If it went well do this, if it went badly do that”.
A concrete example with calendar integration: if the user changes the location of an event, he must call FileMaker and save it in the database. If this was NOT successful (for example, a commit error), the transaction must be canceled and the event returned to its original location so that the user sees that it was not saved. This is called asynchronous programming, and it is something that you must absolutely understand if you want to continue with Javascript.
So in the calendar, here’s what really happens:
- The action in Javascript is called, with immediate actions: what to do if it goes well, what to do if it goes bad.
Internally, these actions are recorded, and Javascript calls FileMaker.
The Javascript code isn’t “running” anymore, there is no more pause, we have actually reached the end of the code.
FileMaker does its job and decides if it wants to tell the Web Viewer if it went well or badly.
The Web Viewer executes the pieces of code (saved in step 1).
In code :
Hi, just ‘one more thing’: you have a typo in the title: PerfomScript = PerformScript.
Cheers!!
Martin R.
Thank you! fixed!