Question

Working with the new Notes 9.x calendar functions but having trouble with recurring meetings. Want to list all calendar events between two datetime values but recurring events show the first event but not the event that falls in my date range.

Programming is like this:

    Pid = "DAETNYR"
starttime = "2014-03-14T6:00:00Z"
endtime = "2014-03-14T19:00:00Z" 

Set PersonDoc = NabHelp.SearchForPersonDoc(Pid)

server1 = PersonDoc.MailServer(0)
server1 = "TestServer1/IA/Servers/USA"
file1 = PersonDoc.MailFile(0)

Set UserMailDb = New NotesDatabase(server1, file1)

Set cal = Session.getCalendar(UserMailDb)


Set StartDate = New NotesDateTime( StartTime ) 
Set EndDate = New NotesDateTime( EndTime )

ForAll cale In cal.getEntries(StartDate, EndDate)

    calestr = cale.ReadRange(StartDate, EndDate)

    i = InStr(calestr, "RECURRENCE-ID:")
    stop    
    If i > 0 Then
        recurid = Mid$(calestr, i + 14, 16)
    End If

    If recurid = "" Then
        Set caldoc = cale.Getasdocument()
    Else
        Set caldoc = cale.Getasdocument(0, recurid)
    End If

End ForAll

Do I read through calestr to find each recurid and test it against the date range? Any ideas?

Was it helpful?

Solution

The object model is a little tricky. A NotesCalendarEntry is a single object representing all the instances of a recurring event. As your sample shows, you can get the document associated with a single instance [cale.Getasdocument(0, recurid)], but you need to know the recurrence ID first.

The problem is NotesCalendar.getEntries() doesn't tell you anything about which recurrence ID falls in the given date range. (By the way, your sample includes this: cale.ReadRange(StartDate, EndDate). I'm not sure what that does since there is no ReadRange() method for NotesCalendarEntry.)

It would be better for you to use NotesCalendar.readRange(). That returns an iCalendar string listing all the events in the range including the recurrence IDs of specific instances. For example, here is some sample output:

BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART:20140314T130000Z
DTEND:20140314T140000Z
TRANSP:OPAQUE
RECURRENCE-ID:20140314T130000Z
DTSTAMP:20140314T121932Z
SEQUENCE:0
CLASS:PUBLIC
SUMMARY:Two week sabbatical
LOCATION:Off site
UID:A56ADC092EA2323285257C75006B2B3F-Lotus_Notes_Generated
X-LOTUS-SUMMARYDATAONLY:TRUE
X-LOTUS-APPTTYPE:0
END:VEVENT
BEGIN:VEVENT
DTSTART:20140315T130000Z
DTEND:20140315T140000Z
TRANSP:OPAQUE
RECURRENCE-ID:20140315T130000Z
DTSTAMP:20140314T121932Z
SEQUENCE:0
CLASS:PUBLIC
SUMMARY:Two week sabbatical
LOCATION:Off site
UID:A56ADC092EA2323285257C75006B2B3F-Lotus_Notes_Generated
X-LOTUS-SUMMARYDATAONLY:TRUE
X-LOTUS-APPTTYPE:0
END:VEVENT
END:VCALENDAR

That shows two event instances with the same UID, but different recurrence IDs. Of course, this is just the summary data for each instance. You can read the instance details like this (in Java):

NotesCalendarEntry entry = cal.getEntry("A56ADC092EA2323285257C75006B2B3F-Lotus_Notes_Generated");
String instanceOne = entry.read("20140314T130000Z");
String instanceTwo = entry.read("20140315T130000Z");

All of the above assumes you can parse the iCalendar format returned by NotesCalendar.readRange(). That's easy in Java with a library like ical4j. It's a bit more difficult with LotusScript, but it's worth the effort. The new NotesCalendar classes make heavy use of iCalendar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top