Tips & Tricks - Creating an ICS Calendar File

This post shows you how to use a Groovy script to write appointment details (from, to, location, title, description) to an iCalendar file and save it to a file field in the same record. The iCalendar file can then be sent via email, for example, or downloaded from the portal application.

Application

You can download our sample application (Intrexx version 12.0.0 or later) with the process here and then import it as usual. The included process is disabled during import—it must be enabled either immediately upon import or later in the "Processes" module via the "Process" main menu so that the application functions as intended.

When you open the "Tips & Tricks - Create ICS Calendar File" application in the "Applications" module, you'll find the following input fields on the input page, which are linked to the corresponding data fields:

  • Title

  • Location

  • Start (Date & Time)

  • End (Date & Time)

  • Description

For simplicity's sake, all of these input fields are required. This way, NULL values do not need to be handled in the process. In addition, the data group contains a "File" field, in which an .ics file is stored for each generated data record.

In addition, the application includes a "Appointment Details" view, which can be opened in the browser by clicking on the title of a record in the table on the "Overview" home page. You can also download the .ics file from this page.

Process

Open the "Tips & Tricks - Create an ICS Calendar File" process in the "Processes" module. The first element in the process chain is a data group event handler that responds to the insertion and modification of records in the application.

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

            import de.uplanet.util.ISODateTimeUtil

def strFileName     = "Appointment"
def guidTermin      = 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 City<string> */
def strDescription  = g_record["594374366FD2600AE013B5357320CC0214BB197E"].value /* datafield Description<text> */
def tsStart         = g_record["0582AD37E755C68CCC0986E63BD26BA2BAE4447C"].value /* datafield Begin <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
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 of the datafield*/


g_dgFile.copy(guid: strExportfileFieldGuid, id: guidTermin, file: tempFile.getAbsolutePath(), name: strFileName + ".ics",  mode: "replace",
    triggerWorkflow: false)

tempFile.delete()
        

Replace the GUIDs listed here as needed. with the corresponding GUIDs from your application. You can find and insert these GUIDs directly in the editor in the Application Structure section. Then save the process.

The Application in the Browser

Here is a list of all the records that have been created. Clicking on a record's title opens the view page, from which you can download or open the ICS file.

iCalendar

Of course, you can add additional iCalendar properties to your output object and, for example, include a reminder feature for your event. Numerous iCalendar tutorials provide examples.