Manage Appointments

This application demonstrates how:

  1. How to logon to an EWS Session using a profile.
  2. How to get all appointments
  3. How to use filters to only get appointments within a date range
  4. How to use the calendar view to also retrieve occurrences of recurring appointments
  5. How to create new appointments
  6. How to delete appointments
  7. How to invite recipients to meetings
  8. How to create recurring appointments

Create a date filter:


      if (not chkBxCalendarView.Checked) and (dtEndDate.DateTime > dtStartDate.DateTime) then
      begin
        // Create the restriction (only needed when the CalendarView is not checked as that already contains a date filter)
        RestrictionAnd := FContentTable.CreateRestriction(rtAnd) as IRwEWSRestrictionAnd;

        RestrictionProperty1 := FContentTable.CreateRestriction(rtCompare) as IRwEWSRestrictionCompare;
        RestrictionProperty1.FieldDef := FLD_CALENDAR_START;
        RestrictionProperty1.CompareOperator := opIsGreaterThanOrEqualTo;
        RestrictionProperty1.Value := RwUTCToLocal(Trunc(dtStartDate.DateTime));

        RestrictionProperty2 := FContentTable.CreateRestriction(rtCompare) as IRwEWSRestrictionCompare;
        RestrictionProperty2.FieldDef := FLD_CALENDAR_END;
        RestrictionProperty2.CompareOperator := opIsLessThanOrEqualTo;
        RestrictionProperty2.Value := RwUTCToLocal(Trunc(dtEndDate.DateTime)+1);

        // The restriction below can be used to filter out recurring event
        // when enabled only the recurring masters will be returned
        // RestrictionExists := FContentTable.CreateRestriction(rtExists) as IRwEWSRestrictionExists;
        // RestrictionExists.FieldDef := EFLD_APPT_RECURRENCYPATTERN;

        RestrictionAnd.AddRestriction(RestrictionProperty1);
        RestrictionAnd.AddRestriction(RestrictionProperty2);
        // RestrictionAnd.AddRestriction(RestrictionExists);

        // apply the restriction
        FContentTable.Filter(RestrictionAnd);
      end;

Handle the creation of a new appointment:


procedure TFrmMain.EWSFolderEventsItemCreated(AFolder: IRwEWSFolder;
  const ATimeStamp: TDateTime; const AId,
  AParentFolderId: TItemId);
var
  lvItem: TListItem;
  Data: TRwListItemData;
  NewItem: IRwEWSCalendarItem;
begin
  if AFolder.ID.Id = FCalendarFolderId.Id then
  begin
    NewItem := FMsgStore.GetItem(AId) as IRwEWSCalendarItem;

    lvItem := lvAppointments.Items.Add;
    Data := TRwListItemData.Create(lvItem);

    Data.MsgStore    := FMsgStore;
    Data.ItemId      := AId;
    Data.Subject     := NewItem.Subject;
    Data.Recurring   := NewItem.IsRecurring;
    Data.AllDay      := NewItem.IsAllDayEvent;

    Data.StartDate   := NewItem.StartDateTime;
    Data.EndDate     := NewItem.EndDateTime;

   if NewItem.HasProperty(EPR_MY_CUSTOM_PROP) then
      RwMsgBoxInfo('A calendar item with the subject "'+NewItem.Subject+'" was created.'#13#10+NewItem.PropertyByName(EPR_MY_CUSTOM_PROP).AsString )
    else
      RwMsgBoxInfo('A calendar item with the subject "'+NewItem.Subject+'" was created.');
  end;
end;

Invite people:


procedure TFrmAppointment.actInviteExecute(Sender: TObject);
{$IFDEF EASYEWS_ENT}
var
  Organizer: IRwEWSRecipient;
  Required, Optional: IRwEWSRecipients;
  i: Integer;
{$ENDIF EASYEWS_ENT}
begin
  {$IFDEF EASYEWS_ENT}
  AddressBookDialog.Session := Self.Session;

  Organizer := (FAppointment.MsgStore as IRwEWSMsgStore).GetIdentity;

  Required := Self.Session.CreateRecipients;
  for i := 0 to FAppointment.RequiredAttendees.Attendee.Count-1 do
    if FAppointment.RequiredAttendees.Attendee.Items[i].Mailbox.EmailAddress <> Organizer.EmailAddress then
      Required.Add(FAppointment.RequiredAttendees.Attendee.Items[i].Mailbox.EmailAddress);

  Optional := Self.Session.CreateRecipients;
  for i := 0 to FAppointment.OptionalAttendees.Attendee.Count-1 do
    Optional.Add(FAppointment.OptionalAttendees.Attendee.Items[i].Mailbox.EmailAddress);

  AddressBookDialog.Buttons := [btnTo, btnCC];
  AddressBookDialog.ButtonNames[btnTo] := 'Required';
  AddressBookDialog.ButtonNames[btnCC] := 'Optional';
  AddressBookDialog.Recipients[btnTo] := Required;
  AddressBookDialog.Recipients[btnCC] := Optional;
  if AddressBookDialog.Execute(True) then
  begin
    FAppointment.ModifyRequiredAttendees(Required);
    FAppointment.ModifyOptionalAttendees(Optional);
  end;

  ResetLbInfo;
  {$ENDIF EASYEWS_ENT}
end;

Screenshot1:


Back to Examples