How are Events Loaded?

How Can We Help?
Categories

This article describes the mechanism to find and filter events to show on the calendar.

Every time the calendar loads (“load”), the refresh button is clicked (“refresh”) or the view or date is changed (“navigate”) the calendar:

  1. finds events to load using the soSIMPLE Calendar AddOn Actions script
  2. creates a JSON array of the events, and
  3. loads them on the calendar using soS Calendar Load Events script

soSIMPLE Calendar uses the “Execute FileMaker Data API” script step to find events. Despite its name, this script step isn’t actually using the FileMaker Data API as deployed on FileMaker Server, and in fact doesn’t even require FileMaker Server. It’s named after the Data API because it uses the same underlying technology, the same query format and the same result format as this tool.

Execute FileMaker Data API

In broad strokes, this script step works like this:

  1. build a query,
  2. include the query as part of a JSON object,
  3. execute this step with the JSON object
  4. loop through the resulting JSON object to turn it into a soSIMPLE Calendar events object.
Build a query:

This describes the query steps we use in soSIMPLE Calendar Actions to get the events for the calendar using the Execute FileMaker Data API script step:

$min_date and $max_date are from the JSON script parameter. They represent the date range that’s being displayed on the calendar when the script is run.

$selected_calendars is the value of the field “soSIMPLE Calendar Settings::zg_selected_calendars”. This is a global field that is updated as calendar names are selected on the “Selected Calendars” web viewer next to the soSIMPLE Calendar. The values are foreign keys stored in each event (in our default events table, it’s in the field “zk_F_Calendar_Name”).

$selected_calendars will also include a special string “showunassigned” if “Show Unassigned Events” is checked off in the calendar selector.

The query portion for the Execute FileMaker Data API will look something like this with each request being it’s own JSON object:

[
      {
         "Date Start": "1/1/2021...2/1/2021",
         "zk_F_Calendar_Name":"1234",
         "Display FLAG": 1
      },
      {
         "Date End": "1/1/2021...2/1/2021",
         "zk_F_Calendar_Name":"1234",
         "Display FLAG": 1
      },
      ...
]

This variable is put together with the rest of the JSON used by this script step. The final result will look something like this:

{
  "layouts": "event",
  "limit" : 500,
  "offset" : 1,
  "query" : [
      {
         "Date Start": "1/1/2021...2/1/2021",
         "zk_F_Calendar_Name":"1234",
         "Display FLAG": 1
      },
      {
         "Date End": "1/1/2021...2/1/2021",
         "zk_F_Calendar_Name":"1234",
         "Display FLAG": 1
      },
      ...
  ]
}

When this script is run, you’ll get a result back that will look something like this:

{
     "response" :{
            "dataInfo":{...}, 
            "data":[...]}, 
     "messages":[...]
}

The calendar events we’re looking for are buried in response > data. (The actual data from each record is in response > data > fieldData).

Information about the results, like how many records were found, are in response > dataInfo. Finally, messages will show any errors encountered in getting the events.

So our next series of steps is looping through the result, filtering out events by Resources if we’ve selected that option (click the gear icon next to the calendar to see the Resource filter), and build a new JSON object from the result.

The JSON record set is then passed as a parameter to the script, soS Calendar Load Events in the very last step of the Actions script.

The JSON parameter is in the format:

{
   "primary_event": {<first JSON event object>}, 
   "all_events": [
        {<event object 2>},
        {<event object 3>}, 
         ...
        ],
   "effect": "load"
}

Perform Find

We’ve found Execute FileMaker Data API to be more efficient (and as a result, faster) than the alternative. But if you’re testing out different filters or trying things that would be challenging to set up in the Data API, or you’re just not comfortable using that method, then Perform Find is for you.

The overview for that method is:

  1. Open a window offscreen
  2. Go to the Events layout
  3. Create find requests for the date range, calendar, and filters.
  4. Perform Find
  5. Loop through the found set and create soSIMPLE Event object.
  6. Pass resulting JSON to the script, soS Calendar Load Events, as above.

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?