none
How to retrieve the master task associated to a completed recurring task? RRS feed

  • Question

  • Hello,

    I'm subscribed to the ProcessItemAdd event in order to catch new Task added in a folder. 

    In this folder user can create simple tasks and recurring task. For recurring taks, Outlook regenerates new occurrences every time the user clicks on "Mark as complete" or "skip" in the main recurring task. So, in the folder for a recurring task, I can find : the master task, skipped tasks, and completed tasks.

    Outlook spy shows me there's no difference between completed tasks and the associated master, except one parameter : TaskDeadOccurrence (http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/8109000B") This parameter is set to false for the master task and true for completed task. This helps me to make difference between two tasks. 

    My point is, when the user clicks on  a recurring task and then "MArk as complete" a new completed task is created and the ProcessItemAdd event is launched and captured. Then, I need to retrieve the master task associated to the completed task. 

    How can I do this? 

    I've been trying with folder.Items.Find but, as all items have the same properties values (except Start and Due dates), the function returns me all the tasks. I would like to include the TaskDeadOccurrence property in the Find string filter but an exception is launched.

    Could you please help me?

    Thanks for your help!

       Yolanda


    Wednesday, January 22, 2014 10:44 AM

Answers

All replies

  • Hello Yolanda,

    Task items in Outlook use a different programming model: there is no master or slave task items. You may use the following ways for getting related tasks:

    1. Use the Find method for filtering items. The Filtering Items Using Query Keywords article describes various types of queries. Also you may be interested in the How To: Use Outlook Find and FindNext methods to retrieve Task items which provides a sample code in VB.NET and C#. It is up to you which properties is to use for filtering (uniquely identify series of tasks), for example, it can be a subject with categories.

    2. The GetRecurrencePattern method returns an instance of the RecurrencePattern  object. It provides the Occurences property which returns a corresponding collection of task items. Also the ReccurrencePattern class has the Regenerate property which is used to control the regeneration of the task as each occurrence of a recurring task is completed. It is only valid for tasks.

    Also you may be interested in the Status property of the TaskItem class which returns or sets an OlTaskStatus constant specifying the status for the task (i.e. completed or not).

    Wednesday, January 22, 2014 11:58 AM
  • The PR_SEARCH_KEY property (DASL name http://schemas.microsoft.com/mapi/proptag/0x300B0102) will be the same for both the master (recurring) task and a complete instance.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 22, 2014 1:57 PM
  • Eugene and Dimitry, thanks a lot for your answers.

    I've been working with your elements, and here are some results.

    I use to work with recurrences on Appointments but, for Task the recurrence pattern seems to work a little different. Indeed, pattern.Occurrences returns me the number of occurrences for my task, it doesn't return me all the occurrences as I need. I could try with the function pattern.GetOccurrence(myDate) but the same problem, it returns me only one Task and I need all the Completed Task

    The second option was using items.Find, as the add-in-express post shows, but this works only if subject is different for each recurring item. I can't forbid users to create two recurrent task having the same subject, start and due date, and the same recurrent pattern.  I've been trying with this filter

     string filter = "[ConversationID] = " + task.ConversationID;
    But this generates an exception. Outlook doesn't allow the use of this kind of properties as filter.


    So, I tried with DASL common properties (as ConversationID and PR_SEARCH_KEY) as Dimitry suggested me.

    First of all, I tried with the following filter:

     Outlook.PropertyAccessor pa = task.PropertyAccessor;
     string searchKey =pa.BinaryToString(pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x300B0102"));
     string filter = "@SQL= " + "\"http://schemas.microsoft.com/mapi/proptag/0x300B0102\"= " +"'" + searchKey +"'"+
                                        " AND \"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/8109000B\" = 1";
    
    var finishedItems = folder.Items.Restrict(filter);

    This should return me all the related completed tasks (occurrences from recurring task), but the result is empty.

    Changing the filter to 

    string filter = "@SQL= " \"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/8109000B\" = 1";

    This returns me all the completed task in the folder. It means, the problem is in the PR_SEARCH_KEY. So I tried another filter, this time based on ConversationID DASL property :

    string filter = "@SQL= " + "\"http://schemas.microsoft.com/mapi/proptag/0x30130102\"= " +"'" + task.ConversationID +"'"+
                                        " AND \"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/8109000B\" = 1";
    
    I obtained the same result. An empty list. 

    I have the impression to deal with the dark side of the force. I don't understand how can I achieve my goal!?!

    Any other suggestions? Help is highly wellcome !!

    Regards

       Yolanda

    Thursday, January 23, 2014 10:20 AM
  • Hello Yolanda,

    Instead, I'd recommend using the Status property for filtering items on the specific date. Then you can iterate via all items and get the ConversationID property manually. Or get the value of the PR_SEARCH_KEY property by using the PropertyAccessor class (see the GetProperty method).

    • Proposed as answer by Eugene Astafiev Wednesday, January 29, 2014 8:34 AM
    • Marked as answer by Yolanda SDF Wednesday, January 29, 2014 8:55 AM
    Thursday, January 23, 2014 11:37 AM
  • Arghhh, I forgot about this - OOM will not let you search on a PT_BINARY property, you'd need to use Extended MAPI or Redemption for that...

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, January 23, 2014 1:53 PM