Calling Scripts in FileMaker from DayBack
You can use custom actions to fire scripts in your FileMaker Pro solution. Prior to FileMaker 19 you'd have needed to use the fmp:// URL format documented here. And that did not work great in WebDirect. But with FileMaker 19 this all gets much simpler and DayBack provides the following function to call a script in the current FileMaker file in Pro, Go, and WebDirect:
dbk.performFileMakerScript('ScriptName', event.timeStart);
Here's what that looks like as a button action in DayBack, calling a simple FileMaker script named "Show Dialog":
You can learn more about adding buttons to DayBack here: custom button actions.
Script Parameters
dbk.performFileMakerScript('ScriptName', event)
...and contains a ton of information about the event including all its fields, the field names in FileMaker, the events table occurrence in FileMaker, and the FileMaker layout you selected for this calendar source. All this information is in a single JSON object. Here's an example from a simple event: SampleEvent.json
Once the event or editEvent object is in FileMaker, you can parse out individual fields or attributes from that object using FileMaker's built-in JSON functions. For example, here's the event's description followed by the event's ID in FileMaker:
JSONGetElement ( $MyScriptParameter ; "description" ) & " " & JSONGetElement ( $MyScriptParameter ; "eventID" )<br>
Note that some aspects of the object are arrays, not discrete values. For example, DayBack supports multiple values for both status and resource, so those are arrays in the event and editEvent object, so you'd get their attributes in FileMaker by asking for a list instead of an element. Here's how to get the ist of an event's statuses:
JSONListValues ( $MyScriptParameter ; "status" )
Multiple Script Parameters
Sending the "event" or "editEvent" objects as a script parameter is, in a sense, sending multiple parameters since those objects have so many attributes within them. But you may want to send separate multiple parameters by hand. We recommend passing multiple parameters as JSON so that you can grab specific parameter elements using the FileMaker functions JSONGetElement and JSONListValues.
Here's what that looks like in a button from DayBack, passing two parameters to FileMaker, the event ID and layout name:
dbk.performFileMakerScript('Show Dialog', {ID: event.eventID, layout: event.schedule.layoutName})
In FileMaker, you'd grab the layout name like this:
JSONGetElement ( $MyScriptParameter ; "layout" )<br>
If you want to hard code some parameters in your action, just wrap them in quotes like Reset is here:
dbk.performFileMakerScript('Show Dialog', {ID: event.eventID, operation: "Reset"})<br>
Callbacks & Script Results
dbk.performFileMakerScript('Show Dialog', {ID: event.eventID, layout: event.schedule.layoutName}, function(result){alert(result.payload)})
Here's what it looks like to click that button, perform the FileMaker script, and then get a result back in DayBack:
We hope this helps you build great interactions between FileMaker and DayBack! Please get in touch if you need help.