Home : J-Integra for Exchange : CDO Filter on AppointmentItems
Q61643 - HOWTO: CDO Filter on AppointmentItems

CDO Filter on AppointmentItems

According to Microsoft Knowledge Base Article - 192404, when filtering on a collection of Collaboration Data Objects (CDO) AppoinmentItems, the Start and End dates must be reversed to make the filter work as expected.

The following example maps the VB code in the article 192404 to Java.

VB

'You must add a Reference to Microsoft CDO version 1.21.
Set objSession = CreateObject("MAPI.Session")

objSession.Logon
Set objCalendar = objSession.GetDefaultFolder(MAPI.CdoDefaultFolderCalendar)
Set oMsgColl = objCalendar.Messages

Set oMsgFilter = oMsgColl.Filter
oMsgFilter.Fields.Add CdoPR_START_DATE, "10/1/06"
oMsgFilter.Fields.Add CdoPR_END_DATE, "9/1/06"

Set oAppt = oMsgColl.GetFirst
MsgBox oAppt.Subject

Do While (Not oAppt Is Nothing)
  MsgBox oAppt.Subject
  Set oAppt = oMsgColl.GetNext
Loop
objSession.Logoff

Java

import com.intrinsyc.cdo.*;
import com.linar.jintegra.AuthInfo;

public class CalendarFilter {

    //TODO: Change the following parameters based on your setup and configuration
    static String domain            = "MYDOMAIN";
    static String user              = "USERNAME";
    static String password          = "PASSWORD";
    static String CDOmachine        = "0.0.0.0";
    static String exchangeServer    = "0.0.0.0";
    static String mailbox           = "MAILBOX";

  public void run() {
    boolean loggedon = false;
    Session cdoSession = null;
    try {
      AuthInfo.setDefault(domain, user, password);
      cdoSession = new Session(CDOmachine);

      // Logon to the Exchange Server
      cdoSession.logon(null, null, new Boolean(false), new Boolean(true),
                    new Integer(0), new Boolean(true),
                    exchangeServer + "\n" + mailbox);
      loggedon = true;

      System.out.println("Got CDO session");
      Folder objCalendar = new FolderProxy(
        cdoSession.getDefaultFolder(
        new Integer(CdoDefaultFolderTypes.CdoDefaultFolderCalendar))
      );
      Messages oMsgColl = new MessagesProxy(objCalendar.getMessages());
      MessageFilter oMsgFilter = new MessageFilterProxy(oMsgColl.getFilter());

      /* Reference:
       * http://support.microsoft.com/?kbid=192404
       */
      new FieldsProxy(oMsgFilter.getFields()).add(
      new Integer(CdoPropTags.CdoPR_START_DATE),
        new String("10/1/06"), // Remember to reverse the date
        null, null
      );
      new FieldsProxy(oMsgFilter.getFields()).add(
        new Integer(CdoPropTags.CdoPR_END_DATE),
        new String("9/1/06"), // Remember to reverse the date
        null, null
      );
      AppointmentItem oAppt = new AppointmentItemProxy(
        oMsgColl.getFirst(oMsgFilter)
      );
      System.out.println("Subject: " + oAppt.getSubject());
    } catch (IllegalArgumentException e) {
      System.out.println(
        "No appointment found.\n" +
        "Make sure there is at least one appointment exists in you filter.\n"
      );
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (loggedon == true) {
        try {
          System.out.println("Logging off from Exchange.");
          cdoSession.logoff();
        } catch(Exception ex) {
          ex.printStackTrace();
        }
      }
    }
  }

  public static void main(String[] args) {
    CalendarFilter example = new CalendarFilter();
    example.run();
  }
}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 12/1/2008.
Last Modified by J-Integra KB Admin.
Article has been viewed 17384 times.
Rated 4 out of 10 based on 7 votes.
Print Article
Email Article