Tips & Tricks - Generate ICS calendar file

This workshop shows you how you can write appointment values (from, to, location, title, description) to an iCalendar file and save this in a file field of the same data record. The iCalendar file can, for example, be sent via email or downloaded in the portal application.

Application

You can download our example application with its process here and import it afterwards as usual. The included process is deactivated when it is imported and needs to either be activated during the import or activated later in the Processes module via the Process menu so that the application functions as intended.

When you open the "Tips & Tricks - Generate ICS calendar file" application in the Applications module, you will find the following edit fields, which are linked to the corresponding data fields, are on the edit page:

  • Title

  • City

  • Start (type: Date & Time)

  • End (type: Date & Time)

  • Description

For the sake of simplicity all edit fields are mandatory. In this way, NULL values do not need to be handled in the process. Additionally, the data group contains the file field "File" where an .ics file for each generated data record is stored.

Furthermore, the application contains the view page "Appointment details" which can be opened in the browser by clicking on the title of a data record in the table on the "Overview" page. The .ics file can be downloaded from this view page.

Process

Open the process "Tips & Tricks - Generate ICS calendar file" in the Processes module. The first element in the process chain is a Data group event handler which responds when data records are added or edited in the application.

The second process element is a Groovy action. The following script is performed here:

import de.uplanet.lucy.server.businesslogic.util.FileUCHelper
import de.uplanet.util.ISODateTimeUtil

def strFileName     = "Termin"
def guidTermin      = g_record["725D4B79458105CD706F078AE07468D6475F9E24"].value /* datafield (PK) (S) ID <string> */
def strSummary      = g_record["C7366F979C6884FA97FAB3DA5EE60B9C0E98DC3A"].value /* datafield Titel <string> */
def strLocation     = g_record["2616A42ADF3D2A3CB68E44864CD72C76852746A1"].value /* datafield Ort <string> */
def strDescription  = g_record["594374366FD2600AE013B5357320CC0214BB197E"].value /* datafield Beschreibung <text> */
def tsStart         = g_record["0582AD37E755C68CCC0986E63BD26BA2BAE4447C"].value /* datafield Beginn <datetime> */
def tsEnd           = g_record["7C8CEAA2652F028E4A95F726627466037CDADD35"].value /* datafield Ende <datetime> */
def tsStamp         = now().withoutFractionalSeconds
def isoUtil = ISODateTimeUtil.newInstance()
def strStart        = isoUtil.formatISODateTime(tsStart)
def strEnd          = isoUtil.formatISODateTime(tsEnd)
def strStamp        = isoUtil.formatISODateTime(tsStamp)
def tempFile = File.createTempFile(strFileName, ".ics")

def strOutput = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//myInstitution//myTopic
METHOD:PUBLISH
BEGIN:VEVENT
SEQUENCE:0
UID:${guidTermin}
SUMMARY:${strSummary}
DESCRIPTION:${strDescription}
DTSTAMP:${strStamp}
LAST-MODIFIED:${strStamp}
DTSTART:${strStart}
DTEND:${strEnd}
LOCATION:${strLocation}
END:VEVENT
END:VCALENDAR
"""

tempFile.withWriter("Cp1252") {out ->    out.append(strOutput)
}

def strExportfileFieldGuid     = "1983BBED4A02FFBF2EBB6C265741BDA76C1AC94A" /* datafield File <file> - GUID des Datenfelds*/

FileUCHelper.copyFileToIntrexx(g_context, tempFile.getAbsolutePath(), strExportfileFieldGuid, guidTermin, strFileName + ".ics" , false)

tempFile.delete()

If required, replace the GUIDs stated here with the corresponding GUIDs from your application. You can identify and insert these GUIDs directly in the editor via the application structure area. Then save the process.

The application in the browser

A list of all created data records is shown here. Click on the title of a data record to open the view page where the ICS file can be downloaded or opened.

iCalendar

Of course, you can add additional iCalendar properties to your output objects and add a reminder function to your appointment. Numerous iCalendar tutorials provide examples of this.