Export .ics Calendar Files

by dougalder

EXPORT ICS CALENDAR FORMAT FILES

The purpose of this module and scripts are to export an .ics file for importing into Calendar applications. The scripts anticipate Single Event or Batch event export. The Main script has a branch for Saving the export file to disk (and opening in the local calendar app) or Emailing the event file. .ics files can be read by most calendar apps such as Google Calendar, Apple Calendar, Microsoft Outlook etc. The script is designed for integration with data tables that include a Start Date, Start Time, End Time, Event Name and Event Description at a minimum.

Download Module

downloaddemo.png

Why use a Virtual List to Export this file?

The reason for using the Virtual List technique is because of UTF-8 text formatting issues. Export Field Contents generates a UTF-16 formatted text file, which some Calendar apps don’t see as valid. Export Records has the option of generating a UTF-8 formatted text file, which Calendar apps accept. The export should work on Mac/Windows and iOS. The export file type is set to Windows ANSI, which seems to work on both platforms.

TL;DNR

REQUIRED VERSION OF FILEMAKER – created in FileMaker Pro 13, but could probably run in FM12 or be rebuilt for FM7 format.

1) IMPORT VIRTUAL_LIST_UTILITY DATA TABLE

Import or recreate the Virtual_List_Utility data table in your solution.

REQUIRED FIELDS – Virtual_List_Utility table should have two fields:

  • ID_VL (auto-entry serial number field)
  • virtual_list – a calculation field – GetValue($$virtual_list; ID_VL)

2) UUID FIELD – If you don’t already have a UUID field, add one to your EVENTS table using FileMaker 13’s Get(UUID).

  • A UUID will help identify the record when you reimport the same record and have the contents match up.
  • If you are working in earlier versions of FileMaker, recreating this script set, there are Custom Functions to create UUIDs (www. briandunning.com).
  • Once you add a UUID field, remember to go back and enter a UUID for every record created before the addition of the UUID field.

3) IMPORT SCRIPTS – Copy and Paste (or recreate) the ‘Export ICS Files’ Folder of scripts in to your solution.

4) EDIT REQUIRED FIELDS – In the REQUIRED FIELDS Script, map your local date, time, description etc., fields to the approprirate script variables.

5) CREATE OR COPY BUTTON – Copy or create a button in your solution that calls the ICS Export script.

  • Place the button on Events layout for users to export Event info to other calendar applications that support the Calendar (.ics) format.

6) ADD A VALUE LIST called ‘1’ with a value of 1. Set the ‘All Day’ Field to be a checkbox using this value list.

7) TEST

  • TROUBLESHOOTING:
    • Use the script debugger to walk through the steps. See what the variables are being set to.
    • If you have problems with your file, open it with a text editor (TextMate on the Mac is great) and review what is being exported. Compare the generated file to an event exported from iCal or other calendar app.

More detail here: hbase.net

Update 2014-12-23: Version 1.1: Support for All Day and End Date fields. Previous version took a short cut and always made the End Date = the Start Date.  Modified REQUIRED FIELDS script to export different version of file if ‘All Day’ is set to ‘1’.  May be an issue with offset. It has been removed from the ‘All Day’ switch because it was causing issues depending on the time zone.

29 responses to “Export .ics Calendar Files”

  1. Delsing Van Kampen says:

    Interesring stuff!

  2. Stephen says:

    Hello. Thanks for the demo file. Is there any way to have the file open automatically inside one of the calendars without having the user select the calendar? For a single calendar, this isn’t a problem but doing multiple imports per day could be. Ideas? Thanks!

    • dougalder says:

      Hi Stephen,
      Your question reflects my own thoughts on this. I think I tried to do this but got stumped. I exported an ics file from Apple Contacts and opened it with a text editor. I could not see a Calendar classification in it. Then I looked on Wikipedia for their definition of .ics files and saw CATEGORIES:MEETING. I tried adding that to the file and reimporting, but it did not work. I still got prompted to add the event to my default calendar (Home).

      Not saying there is not a way, but I didn’t figure it out. Anyone out there who wants to chip in on how to do this, I would be prepared to add it as a new feature.

      • Stephen says:

        Thanks for your reply! I ask because I spent a considerable amount of time one day tweaking the code and I couldn’t figure it out. Then when I saw this, I thought it might have this option. Hopefully someone else could provide an idea.

  3. Peter Gort says:

    Thanks for the great work! Only implementation thing I ran into: Script “Export Calendar – REQUIRED FIELDS Setup {$ExportType}” has a step where it sets a variable “$uuid”. I’m using FileMaker Pro Advanced 13v3 and it spat an error that said that variable name “could not be used”. I opted for simplicity and set it to $uid. Somewhere along the line FileMaker decided that a variable name could not be the same as a Get Function argument, I think.

    • dougalder says:

      Hi Peter,
      Interesting. I never saw that message and didn’t think that the FileMaker engine filtered for the names of variables. Do you have a UUID field in your solution you can set the $UUID variable to? If not, try creating one and then using the Replace command to fill in the blanks of any pre-existing records, so that every record has a UUID. Let me know if you still see this error message. Also, when do you see the message? When you run the script? What platform are you on? Thanks for the feedback. – Doug

  4. Mike says:

    Hi Doug,
    Worked like a champ for events with times. I have many events without times (all-day events). I also have multiple-day events (example: Vacation from Dec 1-Dec 5).
    When these events are created, the timestamps are:
    DTSTAMP:10101T050000Z
    DTSTART:10101T050000Z
    DTEND:10101T050000Z
    These events do not get added to the calendar. Any suggestions on how to handle these all-day or multiple-day events?
    Thanks, Mike

  5. Edward says:

    We have implemented this but run into an issue with iOS8 – when we email the ics file to ourself from Go it refuses to open in iCal. If we run the same method from FMP13 client on a Mac, the email comes through to the iPad and will open the ics in iCal with no problem….. Very frustrating. Is this an iOS issue or something we’re missing?
    Thanks in advance

    • dougalder says:

      Hi Edward,

      I just tested this on my iPad running iOS 8 and it seems to work fine. What are you seeing when you send yourself an email and then click the ics file to add it to your calendar on the iPhone/iPad?

  6. Bob Miller says:

    I have the same issue: email of .ics from FMGo can’t be imported into calendar app. But same event emailed from the FMP13 on my Mac will open in calendar.
    The icon looks different. And the file from iPhone is half the size of the one from the desktop Mac.

    • dougalder says:

      People seem to be seeing different results for this on the iOS. Perhaps on FMGo it would be worth trying to export a global field instead of using the virtual list? Add an if statement to the main script. If iOS, then set global field and Export Field Contents. I don’t have time to look at this right now and it is difficult for me to test, because it seems to work fine on my devices.

  7. Sal Marano says:

    I really enjoy your work on these solutions, and the Export calendar files works as claimed. I have one issue, I would like to attach an email address automatically and the Send mail script will not allow me to add that I get an error message that the table is not related. How can I overcome this without messing up your programing. Can I Relate the Virtual list to the Contact file to pull the information over? Or is there another method I should employ.

    • dougalder says:

      Glad you are finding the solution useful.

      If you want to send the Contact info to the same person each time, just ‘hard code’ it into the ‘To:’ field of the Send Mail step.
      To send it to a Contact in another database, create a relationship between the Calendar and the Contacts and use the field from that database, something like: Calender_Contacts~ID_Contact::Email.

      • Sal Marano says:

        Thank you for the reply, I too am having issues with the import into IPAD calendar, it comes up with a message “This invitation data is out of date.” You can open it in WEEK VIEW Calendar AP by forcing it. You can open it if emailed just will not open when you ask it to open.

  8. Yilbber says:

    For some reason the script keeps complaining that I have no Title and Description set, Despite my Title being set, Description being set, and following the instructions, What could be causing this error? I think I have an issue since I have a field that uses @

    • dougalder says:

      Look in the script called “Export Calendar – REQUIRED FIELDS Setup {$ExportType}”.

      Check under the comment:

      ————–TEST RECORD FOR REQUIRED FIELDS——————

      It is looking for these fields:
      IsEmpty($$EventSummary) or
      IsEmpty($EventStartDate) or
      IsEmpty($EventStartTime) or
      IsEmpty($EventEndTime) or
      IsEmpty($uuid)

      If you missed a step and did not set a field to each of these script variables Event Summary, Start Date, End Date, Start Time, End Time, you will get this error message.

  9. Ian Renwick says:

    Worked first time when I built it into an existing solution! Brilliant. But wait, there’s more….
    I then added a field to enable the user to select either EVENT or REMINDER.
    In the Export Calendar – REQUIRED FIELDS Setup {$ExportType} script I then:
    Added a variable called $EventOrReminder that captured the value of the field I’d added
    I then modified the variable $Body so that “BEGIN:VEVENT” became “BEGIN:V” & $EventOrReminder.
    I also changed “¶END:VEVENT to “¶END:V” & $EventOrReminder.
    Depending on which option is selected I can now get an entry in either OSX Calendar or Reminders application or both!

  10. Ian Renwick says:

    Oops, the second line should read
    I then added a field to enable the user to select either EVENT or TODO

    Explanation
    VEVENT is used to begin or end a Calendar event ;
    VTODO is used to begin or end a Reminders item

  11. Fernando says:

    Anyone knows how can I make a UTC time zone adjustments to get your local time?

    Thanks

  12. Stefan Kerkhofs says:

    I have implemented this in my solution and works perfectly – thank you very much for sharing.
    What I would like to do now is add an attachment to the event, for example a PDF stored in a container.
    Is this possible?
    I tried using the Base64Encode and Base64Decode functions to convert my attachment to text and then adding that in the body after the keyword ATTACH but could not get this to work.
    Thanks.

  13. Donald says:

    Thanks for making this module! It worked 99% perfectly out of the box!

    I had to change a couple of things to make it work for me on events that have no start + end time, both of which in the script titled “Export Calendar – REQUIRED FIELDS Setup {$ExportType}”:

    line 39, in the custom calc, I had to change the ts_begin and ts_end calcs to use GetAsTImeStamp(), since TimeStamp() wasn’t working with no start or end time:

    ts_begin = GetAsTimestamp($EventStartDate & $EventStartTime);
    ts_end = GetAsTimestamp($EventEndDate & $EventEndTime);

    In Line 51 I had to modify the error check to only check for start + end time if the event isn’t “all day”:

    IsEmpty($$EventSummary) or IsEmpty($EventStartDate) or IsEmpty($uuid)
    or (
    not $AllDay and (
    IsEmpty($EventStartTime) or IsEmpty($EventEndTime)
    )
    )

    Once I did those things, it worked perfectly! Thanks again for your work on this.

  14. Scott Howard says:

    Thanks, Doug, for a great demo file and clear integration descriptions. Thanks also Donald for your tweaks for timeless events. Both helped me with a client’s solution today.

  15. Gentlemen, I keep getting the message “In order to export a properly formatted calendar file, you need the following fields filled in: Title Description.” I’ve been using Filemaker for years and have checked the demo file HB->Export Calendar Files against my FM15 database of events and I cannot figure out what’s wrong. If I import a week’s events into the demo file and run the scripts it works fine. I just can’t figure this one out. Sorry 🙁

    • dougalder says:

      Obvious question: are those fields filled in?

      Next question, are you running this from the demo file or from your own solution?

      If you moved it to your solution, did you update the fields for export? These fields are in the script called “Export Calendar – REQUIRED FIELDS Setup {$ExportType}”

  16. Thank you. I’ll take another look. Maybe I missed something.

Leave a Reply

Your email address will not be published. Required fields are marked *