Home Ask Login Register

Developers Planet

Your answer is one click away!

Jan Doggen February 2016

How to recreate exceptions of recurring appointment in the proper order?

I have the following issue:

  • Assume a recurring event on 15, 19, 23, 27... February
  • In Exchange the '19' occurrence was moved to 21
  • Next, the '15' occurrence was moved to 20. So it moves past the original start date (19) of the 2nd occurrence

Now if I want to recreate this recurring event in Exchange I first create the master event, i.e. automatically with all its regular occurrences, and then I must modify some of these to create the exceptions in this same order. If I don't do that and first create the '15->20' occurrence, this will fail, because its modified date is past the regular '19' occurrence.
Exchange will give me the Modified occurrence is crossing or overlapping adjacent occurrence error.

But how do I determine the order? In a simple test case the GetItem call for the master event does not give me the ModifiedOccurrences in the order in which they were created:

       <t:ItemId Id="AAMkA[snip]pQAAEA==" ChangeKey="DwA[snip]bix"/>
       <t:ItemId Id="AAMkA[snip]pQAAEA==" ChangeKey="DwA[snip]bix"/>

If I do a GetItem for those two exceptions I see no appointment property that I can use to determine the order in which they were created:

  • LastModifiedTime does not say anything, the exceptions may have been modified repeatedly.


Jan Doggen February 2016

Found the answer. The crucial remark in my question was:

OriginalStart or RecurrenceId (a date equal to OriginalStart) don't work, because this process goes in both directions (the exceptions can also be back in time).

If you split forward and backward occurrence moves and handle them in two blocks, it works. Actually, three blocks:

  1. Remove deleted occurrences

  2. Create occurrences moved forward (Start > OriginalStart) from last date to first date

  3. Create occurrences moved backward (Start < OriginalStart) from first date to last date

Essential parts of the (Delphi XE2) code using Developer Express components:

   TIDDate = class
                FStart   : TDateTime;
                FIndex   : Integer;
                Constructor Create(AOrgStart,AStart: TDateTime; AIndex: Integer);

constructor TIDDate.Create(AOrgStart,AStart: TDateTime; AIndex: Integer);
   FOrgStart := AOrgStart;
   FStart    := AStart;
   FIndex    := AIndex;

function TDataModuleSyncExchange.InsertExchangeMasterEvent(AMasterEvent: TcxSchedulerEvent; var AMasterItemID, AMasterEntryID: String): Boolean;
   lExchOccurrence: TcxSchedulerEvent;
   i              : Integer;
   lDateList      : TObjectList;
   lIDDate        : TIDDate;
   lEventList     : TcxSchedulerEventList;

begin { Main InsertExchangeMasterEvent }
   lEventList := AMasterEvent.GetRecurrenceChain;  // DevEx code

   // 1. Deleted occurrences 
   for i := 0 to lEventList.Count-1 do
      lExchOccurrence := lEventList.Items[i];
      if lExchOccurrence.EventType = etException then
         DeleteExchangeItem(lOccurItemID);  // Own code elsewhere

   // 2. Occurrences moved forward (Start > OriginalStart) from last date to first date
   lDateList := TObjectList.Create(true);
   for i := 0 to lEventList.Count-1 do 

Post Status

Asked in February 2016
Viewed 3,705 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved