Advanced Techniques - 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 dataset. The iCalendar file can, for example, be sent via email or downloaded in the portal 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 "Advanced Techniques - 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: 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 dataset 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 dataset in the table on the "Overview" page. The .ics file can be downloaded from this view page.


Open the process "Advanced Techniques - Generate ICS calendar file" in the Processes module. The first element in the process chain is a Data group event handler which responds when datasets 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     = "Appointment"
def guidAppointment = g_record["725D4B79458105CD706F078AE07468D6475F9E24"].value /* datafield (PK) (S) ID <string> */
def strSummary      = g_record["C7366F979C6884FA97FAB3DA5EE60B9C0E98DC3A"].value /* datafield Title <string> */
def strLocation     = g_record["2616A42ADF3D2A3CB68E44864CD72C76852746A1"].value /* datafield Location <string> */
def strDescription  = g_record["594374366FD2600AE013B5357320CC0214BB197E"].value /* datafield Description <text> */
def tsStart         = g_record["0582AD37E755C68CCC0986E63BD26BA2BAE4447C"].value /* datafield Start <datetime> */
def tsEnd           = g_record["7C8CEAA2652F028E4A95F726627466037CDADD35"].value /* datafield End <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

tempFile.withWriter("Cp1252") {out ->

def strExportfileFieldGuid     = "1983BBED4A02FFBF2EBB6C265741BDA76C1AC94A" /* datafield File <file> - GUID of the data field*/

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

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 datasets is shown here. Click on the title of a dataset to open the view page where the ICS file can be downloaded or opened.


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.