none
Search Tasks by ItemProperties in Outlook 2007 Add-in RRS feed

  • Question

  • Hi, I am working with an Outlook 2007 add-in developed in VS 2008 (C#). Here I need to search tasks in the [Tasks] folder filtering with ItemProperties collection.

    For example: Some tasks in this folder contain custom/user properties that are available in ItemProperties collection. The properties are added using VBA code from another application like below:

    taskItem.ItemProperties.Add("EntityType", olText).value = "Product"
    taskItem.ItemProperties.Add("EntityID", olText).value = "100"
    

    Here taskItem is an instance of a task in this folder.


    Now in the add-in, I need to search for the task using these values (EntityType = "Product", EntityID = "100").

    I got an option to filter the items in a folder like below:

     

       Outlook.MAPIFolder folderTask = null;
       folderTask = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderTasks);
    
       folderTask.CurrentView.Filter = "";
    
    

    But can anyone please let me know how to build the Filter string to search with these user property values?

     

    Thanks in advance...

    -Jahedur Rahman

     

     

     



    Thursday, July 7, 2011 9:30 AM

Answers

  • If you need to get back an object reference then you don't want to use a View.Filter. You want to use Folder.Items.Find() or ..Restrict(). You supply a filter for that and it returns an item (Find) or a filtered Items collection (Restrict).

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Jahedur.Rahman" <=?utf-8?B?SmFoZWR1ci5SYWhtYW4=?=> wrote in message news:fb6458c6-5296-4ccf-a8f3-33b78b590d6d...

    I need to return the TaskItem with the User property names (EntityType = product and EntityID = 100). But I will try to see the filter in the customize view dialog and will update soon.

    Thanks Ken for your kind attention...

    -Jahedur Rahman


    Ken Slovak MVP - Outlook
    Thursday, July 7, 2011 5:23 PM

All replies

  • There are 2 types of filters, those using Outlook property names and those using DASL property tags. What exactly are you trying to do? Do you want to filter a view, or do you want to return a specific TaskItem object?
     
    The easiest way to see how to construct a filter is to go to the customize view dialog and to open the Filter dialog there. In the Advanced tab you can set up the filter you want from the available fields and then view the DASL result in the SQL tab.
     
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Jahedur.Rahman" <=?utf-8?B?SmFoZWR1ci5SYWhtYW4=?=> wrote in message news:7535a767-6b21-44e3-817a-da2594211b05...

    Hi, I am working with an Outlook 2007 add-in developed in VS 2008 (C#). Here I need to search for tasks in the [Tasks] folder filtering with ItemProperties collection.

    For example: Some tasks in this folder contains custom/user properties that are available in ItemProperties collection. The properties are added using VBA code from another application like below:

    taskItem.ItemProperties.Add("EntityType", olText).value = "Product"
    taskItem.ItemProperties.Add("EntityID", olText).value = "100"
    

    Here taskItem is an instance of a task in this folder.


    Now in the add-in, I need to search for the task using these values (EntityType = "Product", EntityID = "100").

    I got an option to filter the items in a folder like below:

       Outlook.MAPIFolder folderTask = null;
       folderTask = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderTasks);
    
       folderTask.CurrentView.Filter = "";
    
    

    But can anyone please let me know how to build the Filter string to search with these user property values?

    Thanks in advance...

    -Jahedur Rahman

     

     

     


    Ken Slovak MVP - Outlook
    Thursday, July 7, 2011 1:42 PM
  • I need to return the TaskItem with the User property names (EntityType = product and EntityID = 100). But I will try to see the filter in the customize view dialog and will update soon.

    Thanks Ken for your kind attention...

    -Jahedur Rahman

    Thursday, July 7, 2011 2:49 PM
  • If you need to get back an object reference then you don't want to use a View.Filter. You want to use Folder.Items.Find() or ..Restrict(). You supply a filter for that and it returns an item (Find) or a filtered Items collection (Restrict).

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Jahedur.Rahman" <=?utf-8?B?SmFoZWR1ci5SYWhtYW4=?=> wrote in message news:fb6458c6-5296-4ccf-a8f3-33b78b590d6d...

    I need to return the TaskItem with the User property names (EntityType = product and EntityID = 100). But I will try to see the filter in the customize view dialog and will update soon.

    Thanks Ken for your kind attention...

    -Jahedur Rahman


    Ken Slovak MVP - Outlook
    Thursday, July 7, 2011 5:23 PM
  • Thanks a lot Ken. Restrict() worked perfectly.

    -Jahedur Rahman

    Friday, July 8, 2011 6:46 AM
  • Could you post your solution so others can see how you solved the issue please?
    Wednesday, August 3, 2011 11:57 PM
  • Below is the actual code I have written to filter the tasks with EntityID = 1234...

    string filter = "";
    Outlook.MAPIFolder folderTask
       Outlook.Items items = null;
    
    folderTask = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderTasks);
    
        try
        {
         filter = "[EntityID] = \"" + "1234" + "\"";
         
         items = folderTask.Items.Restrict(filter);
         
        }
        catch (Exception ex)
        {
         //if the user property [EntityID] does not exist in the user profile in outlook, an exception (THE PROPERTY 'PropertyName' IS UNKNOWN) will be thrown
         //then resume at next step, or else, throw the exception
         if (!(ex.Message.ToUpper().Contains("THE PROPERTY") && ex.Message.ToUpper().Contains("IS UNKNOWN.")))
          throw ex;
        }

    Items will contain a list of items returned after the filter. You can loop through the collection in this variable and cast them to Outlook.TaskItem object.

    -Jahedur Rahman

     




    Thursday, August 4, 2011 3:12 AM