Search code examples
javalotus-noteslotuslotus-formula

Get today's calendar entries in Lotus Notes using Java


I am trying to get the calendar entries for a given day. The code works without error however I am getting a wrong calendar date entry. I am sure the formula is correct but neverthless would appreciate any help on this. Here's the code.

        long startTime;
        long endTime;
        String searchFormula;
        DocumentCollection dc_CalendarEntries;

        System.out.println("Getting default TimeZone");
        TimeZone calTZ = TimeZone.getDefault();
        GregorianCalendar startDay = new GregorianCalendar(calTZ);
        startDay.set(startDay.get(1), startDay.get(2), startDay.get(5), 0, 0, 0);
        startTime = startDay.getTime().getTime();
        GregorianCalendar endDay = new GregorianCalendar(calTZ);
        endDay.setTime(startDay.getTime());
        endDay.add(5, 1);
        endTime = endDay.getTime().getTime();
        System.out.println("Creating Search Formula");

        StringBuffer searchFormulaStringBuffer = new StringBuffer("@IsAvailable(CalendarDateTime)");
        searchFormulaStringBuffer.append(" & StartDateTime >= @Date(").append(startDay.get(1)).append("; ").append(startDay.get(2) + 1).append("; ").append(startDay.get(5)).append("; ").append(startDay.get(10)).append("; ").append(startDay.get(12)).append("; ").append(startDay.get(13)).append(")");
        searchFormulaStringBuffer.append(" & EndDateTime <= @Date(").append(endDay.get(1)).append("; ").append(endDay.get(2) + 1).append("; ").append(endDay.get(5)).append("; ").append(endDay.get(10)).append("; ").append(endDay.get(12)).append("; ").append(endDay.get(13)).append(")");
        searchFormulaStringBuffer.append(" & (AppointmentType = \"3\" | AppointmentType = \"0\")");
        searchFormula = searchFormulaStringBuffer.toString();           
        System.out.println(searchFormula);
        dc_CalendarEntries = db_Mail.search(searchFormula); 

This is what is the formula that is applied.

@IsAvailable(CalendarDateTime) & StartDateTime >= @Date(2009; 10; 3; 0; 0; 0) & EndDateTime <= @Date(2009; 10; 4; 0; 0; 0) & (AppointmentType = "3" | AppointmentType = "0")

I get the following entries.

Test Project daily checkpoint 2009-09-08
This is a Test Meeting 2009-10-03

The second entry is correct and is fine but for some strange reason the first entry keeps popping up regardless of the date i give. I am not sure if its a coding issue or some config issue in my notes.


Solution

  • You need to be careful of repeating calendar entries, as these will have start and end datetime field values which map to the first entry of the series.