Script to run on interaction
(or “soSIMPLE Action” script).
- REQUIRED for Standalone mode or Client-Side Scripting.
- Optional for “Server-Side Async” method (script runs server-side).
- This script runs every time you:
- drag an existing event to edit an event on the calendar
- drag a blank area to create a new event on the calendar
- double-click an event to open it
- click the delete icon or the details icon (to open it) in either the event toolbar or the quick info panel (these are enabled by (“Event Action Icons” and “Touch Enhancements” respectively in calendar options).
This is THE script that handles all user interaction with your calendar.
When you copy & paste scripts from soSIMPLE Calendar Settings into your solution, this script is called “soSIMPLE Calendar Actions.” When you copy & paste it from soSIMPLE Calendar Settings, all of your data source field names and data layout name are included in the script, so it should run without modification. Of course you’ll likely want to make some modifications to customize it the way you want.
note: There is also an alternate script called “soSIMPLE Calendar Actions (old style).” The only difference is that the new style uses “set field by name” script step, and the old one does not. That also means that it won’t run without first modifying the script to point to your fields.
USER FIELDS AND LAYOUT:
These lines are defined automatically when you copy & paste the scripts from soSIMPLE Calendar Settings. You can also copy & paste just these two lines by choosing “Copy just Variable Steps” from the “Use in FileMaker Pro” screen. [standalone] [server-powered]
- These variables are created by soSIMPLE Calendar Settings based on your Data Source settings
- You can change them to the correct field and the correct user entry layout, if you’ve changed them.
- IMPORTANT: the rest of the script depends on these settings to perform searches and set data
Set Variable [$data_layout_name; Value:”data fields”]
Set Variable [$entry_layout_name; Value:If ( not IsEmpty ( $$data_entry_layout ) ; $$data_entry_layout ; $data_layout_name )]
Set Variable [$field_names; Value:Let ([ $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_f…]
- — these variables are automatically set when this script runs from the calendar
- — no need to use get(scriptparameter) – these are set automatically when the script runs from the calendar.
- — you can use these variables for evaluating, searching or setting data
- $event_type = new,edit,open,delete;
- $event_id = key from fm or random for existing event;
- $from = start timestamp;
- $to = end timestamp;
- $from_utc = start timestamp as UTC time;
- $to_utc = end timestamp as UTC time;
- $text = “New event” or edited text of event
- $unit = “undefined” or resource name;
- $readonly = “undefined” or whether or not the event has been defined as read only
- $script = “undefined” or the name of the script assigned to the data source
- $url = the hashtag of the url of the web viewer when the script was run – everything to the right of the “#” (& and = substituted with || and ~~, respectively)
- $untimed = 1 or blank. If untimed is 1, then the start time was not set.
FUNCTIONALITY OF THIS SCRIPT:
If [LeftWords (Get ( ApplicationVersion );1) = “Web”]
This step determines if this is a “Server-SIde Async” calendar.
When using Server-Side Async, soSIMPLE Calendar already knows how to create, update and delete events without using this script.
Our example ignores the rest of this script for Server-Side Async. This allows the natural functions of soSIMPLE Calendar to perform the operation on the server. You can choose to perform server-side script functions by putting steps in this section. For Server-Side Async, this script will run right after the intended action and right before returning the event back to the calendar to update it.
You can use this feature to alter data, for example, or to send an email about an event change.
Run these steps when you’ve dragged in a blank section of the calendar, to create a new event.
Our example script opens a new window, sets the date, time &/or resource information, and pauses for you to finish.
Else If [$event_type=”Edit”]
Run these steps when you’ve dragged an event from one time to another, or one resource to another.
Our example script opens the event in its own window off-screen, changes the information, then closes the window.
Else If [ $event_type=”Open”]
Run these steps when you’ve double-clicked an event to open it.
Our example script opens the event in its own window and pauses it.
Else If [$event_type=”Delete”]
Run these steps when you’ve deleted the event from the calendar.
The default configuration of the calendar does not show a delete button, so this section is rarely used. Instead we delete events from the event window. You can show the delete button in Options by choosing “Delete” from the Event Action Icons.
Refresh the event on the calendar
Perform Script [“Calendar Update Event (event_id)”; Parameter: $id]
This step runs the utility script that updates the event on the calendar. Depending on the type of calendar you’re using and whether you’re using the MBS plugin, this will either refresh the calendar, or just update the event that was modified.