Export Script for Standalone

  • Required for Standalone calendars
    • Exports the events to FileMaker’s temporary directory so that the calendar can access the events.
    • It needs to be exported in a particular format, using JSON.
    • Resources are also exported, using JSON.
  • Ignored for Server-Powered calendars

When you copy & paste scripts from soSIMPLE Calendar Settings into your solution, this script is called “Export Events Standalone.”


The entire purpose of this script is to export your events and resource list into the format required for soSIMPLE Calendar. The resulting format is:

window.datafeed = [
{id:'FA3656FE-A7FD-45C2-A8C5-64159CAFA560',text:'event text event 1',details:'<SPAN STYLE="" >event text event 1</SPAN>',resource:'123',start_date:'12/18/2014 13:11',end_date:'12/18/2014 14:11'},
{id:'FA3656FE-A7FD-45C2-A8C5-64159CAFA561',text:'event text event 2',details:'<SPAN STYLE="" >event text event 2</SPAN>',resource:'123',start_date:'12/18/2014 13:11',end_date:'12/18/2014 14:11'};
var resources = [{label:'resource 1', key:'resource 1'},{label:'resource 2', key: 'resource 2'];

Note: Resources can be used by name only, or can use name/key pairs. If you’re using name/key pairs, the calendar will correctly show the name in the resource columns and timeline rows and will store the resource keys in the resource key field of your events table.



This script REQUIRES the creation of a single calculation field in your event table called data.json. You can copy the data.json script when click “Use in FileMaker Pro/Go” in soSIMPLE Calendar Settings. You must make sure that the “let” variable steps at the top of this field definition line up with the corresponding field in your database.

Let ([
/* assign each variable to a field, leave it blank by making the right side empty quotes ( "" ) */
date_start_field =Date Start;
date_end_field =Date End;
time_start_field =Time Start;
time_end_field =Time End;
event_id_field =Event ID;
event_text_field =Event_Text;
event_details_field =event as shown on calendar;
event_unit_field =Resource;
show_only_field =Display FLAG;
event_color_field =color;
event_text_color_field =textcolor;
paint_color_field=background color;
readonly_field =readonly FLAG;
tooltip_field=event as shown on calendar;

There are other dependencies noted at the top of this script



The first section of the script builds the resource function shown above and stores it in a variable called $resource_function.

#build resource json code from value list
#$resource_function is used in the data.json calculation field
Set Variable [$resource_list; Value: ValueListItems ( "";"Resources" )]
Set Variable [$resource_function; Value: "var resources= ["]
Set Variable [$x; Value:0]
Set Variable [$x; Value:$x +1]
Exit Loop If [$x > ValueCount ($resource_list)]
Set Variable [$resource_id; Value:GetValue($resource_list;$x)]
Set Variable [$resource_name; Value:ExecuteSQL("select Name from RESOURCE where resource_id = ?"; ""; ""; $resource_id)]
Set Variable [$resource_function; Value:$resource_function & "{label:"" & $resource_name & "", key:"" & $resource_id & ""}" & If ($x ≠ ValueCount ($resource_list); ",")]
End Loop
Set Variable [$resource_function; Value:$resource_function & "];"]

The next part of the script performs any finds you’d like to perform (in our example we find records based on global fields like “location”) and exports the single field data.json to the file data.js file in your temporary folder. The data.json field is responsible for compiling the data into a json record, turning it into a function, and appending the $resource_function variable.

Go to Layout [“data fields” (calendar_data)]
#-- only export records two months back
Set Variable [$criteria; Value:">" & Get(CurrentDate)-60]
Enter Find Mode [Restore]
If [not IsEmpty (calendar_data::zg_filter.owner)]
Set Field [calendar_data::owner; calendar_data::zg_filter.owner]
End If
If [not IsEmpty (calendar_data::zg_filter.category)]
Set Field [calendar_data::category; "=="" & calendar_data::zg_filter.category & """]
End If
Set Error Capture [On]
Perform Find []
Sort Records [Restore; No dialog]
Export Records [No dialog; “$data_path”; Unicode (UTF-16)]
Go to Layout [original layout]

The final step returns the full path to the data.js file for the calling script to reference.

Exit Script [Result: $data_path]