Calling Scripts in FileMaker from DayBack


  Related Article

This article explains how to trigger FileMaker scripts from custom actions within DayBack using JavaScript. If you need to trigger JavaScript code within DayBack from FileMaker scripts, please refer to the guide: Calling Scripts in DayBack from FileMaker.

Overview

You can use custom actions in DayBack to trigger scripts within your FileMaker Pro solution. Before FileMaker 19, this required using the fmp:// URL format (documented here), which had limitations, particularly in WebDirect. However, with FileMaker 19 and later, this process is much easier. DayBack provides a function that allows you to call a script in the current FileMaker file across Pro, Go, and WebDirect:

dbk.performFileMakerScript('ScriptName', event.timeStart);

Here’s an example of a button action in DayBack that calls a simple FileMaker script named "Show Dialog":

You can learn more about adding buttons to DayBack here: custom button actions.


Script Parameters

In this example, 'ScriptName' is the name of the FileMaker script you'd like to run and event.timeStart is the script parameter, specifically the event's start time. You can find the object names for all DayBack's fields here: field names in DayBack's event object.

Alternatively, you can send the entire event or editEvent object as your parameter. The event object represents the saved state of the event, while editEvent includes any unsaved changes made in DayBack's popover.

Here's how you might pass the entire event object:

dbk.performFileMakerScript('ScriptName', event)

This approach sends the entire payload of information about the event, including all its fields, the corresponding field names in FileMaker, the event's table occurrence in FileMaker, and the FileMaker layout you selected for this calendar source. All this information is packaged into 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 use FileMaker's built-in JSON functions to extract individual fields or attributes. For example, to retrieve the event's description and its ID in FileMaker:

JSONGetElement ( $MyScriptParameter ; "description" ) & " " & JSONGetElement ( $MyScriptParameter ; "eventID" )

Keep in mind that some aspects of the object, like statuses and resources, are arrays rather than single values. Since DayBack supports multiple values for both status and resource, these are represented as arrays in the event and editEvent objects. To retrieve a list of an event's statuses, you would use:

JSONListValues ( $MyScriptParameter ; "status" )

Multiple Script Parameters

When you send the event or editEvent objects as a script parameter, you're essentially sending multiple parameters, since these objects contain many attributes. However, if you want to pass multiple parameters separately, we recommend sending them as JSON. This approach allows you to easily extract specific elements using FileMaker's JSONGetElement and JSONListValues functions.

Here's an example of how you can pass two parameters—a eventID and a layoutName —from a DayBack button to FileMaker:

dbk.performFileMakerScript('Show Dialog', {ID: event.eventID, layout: event.schedule.layoutName})

In FileMaker, you would retrieve the layout name like this:

JSONGetElement ( $MyScriptParameter ; "layout" )

If you need to hard-code certain parameters in your action, simply enclose them in quotes, as shown here with "Reset" :

dbk.performFileMakerScript('Show Dialog', {ID: event.eventID, operation: "Reset"})

Callbacks & Script Results

The dbk.performFileMakerScript() function mentioned earlier actually accepts an optional third parameter—a callback function that will run in DayBack after the FileMaker script completes. This callback function receives the result of your FileMaker script as its parameter. You can see this in action in the custom scripts used for pulling statuses and resources from FileMaker: status and resource examples.

Here’s a simple example to demonstrate. We'll add an exit script result to our "Show Dialog" script and then display that script result in DayBack using a JavaScript alert. Our button code now looks like this:

dbk.performFileMakerScript('Show Dialog',  {
      ID: event.eventID, 
      layout: event.schedule.layoutName
   }, 
   function(result) { alert(result.payload) }
);

In this example, the alert function will display the result.payload , which is where DayBack stores the result from your FileMaker script.

Here’s our straightforward FileMaker script:

And here’s what it looks like when you click the button, run the FileMaker script, and receive a result back in DayBack:

We hope this guide helps you create seamless interactions between FileMaker and DayBack! Please reach out if you need any assistance.