Restrict on User Properties RRS feed

  • Question

  • can you restrict Outlook items, based on the existance/contents of a User property?

    on start up I only want to check items on which I have set this user property, to help with speed, but

    I can't see how to use the Items.Restrict method on anything other than outlook defined properties.

    Thank  you in advance.

    Monday, March 12, 2012 11:05 AM


All replies

  • Hi,

    as far as I know, you can also search on Custom Properties as long as they resist as Folder Properties:


    If you are using user-defined fields as part of a Find or Restrict clause, the user-defined fields must exist in the folder. Otherwise the code will generate an error stating that the field is unknown. You can add a field to a folder by displaying the Field Chooser and clicking New.

    If you have Custom Properties wich are not exists as Folder-Properties, you may have One-Off-Items.

    Greets - Helmut

    Helmut Obertanner [] []

    Monday, March 12, 2012 11:38 AM
  • How do I code for a user property? I have previously used restrict on an Outlook Defined Property appointments.Items.Restrict(String.Format("[Start] >= '{0}'", dtStart.ToString("g")) + " And " + String.Format("[Start] <= '{0}'", dtEnd.ToString("g"))); But I can't seem to use my user property, also it may very well not exist against every appointment, only the appointments deemed appointments used by my add in.
    Monday, March 12, 2012 11:51 AM
  • use DASL syntax. For example you have user property named Prop1. To seach for items that have this property you should use following code:

    Items.Restrict("SQL=({00020329-0000-0000-C000-000000000046}/Prop1 IS NOT NULL)");

    of course you can change this to =, <>, >=, etc. just like normal SQL queries.

    Monday, March 12, 2012 12:11 PM
  • Does this work if the user property doesn't exist within all appointments, as I have implemented this and get an error of Condition is not valid when trying to run this line of code, I have read through the documentation you have linked, but there don't seem to be any answers there I have literally replaced your user propery value of Prop1 with mine of oCustomer and dropped it into my restrict.
    Monday, March 12, 2012 12:41 PM
  • I see that i forgot to append @ in front of SQL, so it should be:

    Items.Restrict("@SQL=({00020329-0000-0000-C000-000000000046}/Prop1 IS NOT NULL)");

    does it work now?

    • Marked as answer by Vis Xero Monday, March 12, 2012 4:38 PM
    Monday, March 12, 2012 1:07 PM
  • Thank you the @ fixed the error, it now accepts the Parameter, but it's still not returning any results which I am expecting 20 results.  I have 200 + Appointments but only 20 of the appointments have this parameter, which is are the appointments I wish to get into my appointment object.
    Monday, March 12, 2012 2:02 PM
  • When you added your user properties to appointments did you remember to pass 'true' as a flag to add them also on Folder level?
    • Marked as answer by Vis Xero Wednesday, March 14, 2012 9:54 AM
    Monday, March 12, 2012 3:57 PM
  • Thank you DamianD, that was it I'm new to VSTO and all the examples I saw set it to false, so that is what I had done.
    Monday, March 12, 2012 4:38 PM
  • hi, i have the opposite problem.

    the results of retrict are not 0.On the contrary, they are the whole set of appointments as if the restrict did not work .My line is 

    items.restrict ("@SQL=({00020329-0000-0000-C000-000000000046}/orders/0x0000001F like  '"& ordernum &"%')"

    any ideas why restrict is resisting to find a subset?

    Monday, August 1, 2016 2:21 PM
  • Outlook does not like the property type (0x0000001F) and thinks that the property name is "orders/0x0000001F".

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, August 1, 2016 5:52 PM