"Condition is not valid" error on Items.Find for Appointment Item using GlobalAppointmentID as filter
We are getting "Condition is not valid" error on Items.Find for Appointment Item using GlobalAppointmentID as filter.
We are using the filter as: strFilter = "[GlobalAppointmentID] = 'apptidhere'" and getting following exception:
runtime error '-2147352567(80020009)' "Condition is not valid"
Then we have tried finding the Item using DSAL query based on Proptag for GlobalAppointmentID to avoid exception as below:
strFilter = "@SQL=""https://schemas.microsoft.com/mapi/id/{6ED8DA90-450B-101B-98DA-00AA003F1305}/00030102"" = 'ApptIDHere'"
but it would NOT return any Item as result because for both Jet and DASL queries, you cannot restrict on a binary property such as EntryID.
So, Binary properties are NOT SUPPORTED to Find or Restrict Outlook Items.
- Searching Outlook Data
https://msdn.microsoft.com/en-us/library/cc513841.aspx
However, We can store GlobalAppointmentID in UserDefinedProperty to find item based on it using Find or Restrict as a workaround.
Here's what I have done in my sample VBA code and able to get Item from Items.Find using Custom Property :
NOTE: Following programming examples is for illustration only, without warranty either expressed or implied,
including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.
This sample code assumes that you are familiar with the programming language being demonstrated and the tools used
to create and debug procedures.
1: 'Creating Apptointment Item with Custom property.
2: Sub CreateTestAppointmentWithCustomProp()
3: Dim myOlApp As Outlook.Application
4: Dim myItem As Outlook.AppointmentItem
5: Set myOlApp = CreateObject("Outlook.Application")
6: Set myItem = myOlApp.CreateItem(olAppointmentItem)
7: myItem.Start = DateAdd("n", 16, Now)
8: myItem.End = DateAdd("n", 60, myItem.Start)
9: myItem.Subject = "TestAppointment"
10: myItem.ItemProperties.Add "GAI", olText, True
11: myItem.Save
12: myItem.ItemProperties.Item("GAI").Value = myItem.GlobalAppointmentID
13: myItem.Save
14: myItem.Display
15: End Sub
16:
17: 'Finding Item based on Custom Property
18: Sub FindItem()
19: Dim objOutlook As Outlook.Application
20: Set objOutlook = New Outlook.Application
21: Dim objNS As Outlook.NameSpace
22: Set objNS = objOutlook.Session
23: Dim objFolder As Outlook.MAPIFolder
24: Set objFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
25: Dim objAppts As Outlook.Items
26: Set objAppts = objFolder.Items
27: Dim objAppt As Outlook.AppointmentItem
28:
29: Dim strFilter As String
30: strFilter = "@SQL=""https://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/GAI"" = 'ApptIDHere'"
31:
32: Set objAppt = objAppts.Find(strFilter)
33: If objAppt Is Nothing Then
34: MsgBox ("Nothing Found")
35: Else
36: MsgBox ("Appt Found")
37: End If
38: End Sub
To get property tag of your custom property for your DASL query we can use MFCMAPI available @ https://www.codeplex.com/MFCMAPI.
I have also referred following articles:
- Referencing Properties by Namespace
https://msdn.microsoft.com/en-us/library/bb147567.aspx - Enumerating, Searching, and Filtering Items in a Folder
https://msdn.microsoft.com/en-us/library/bb147574.aspx - AppointmentItem.GlobalAppointmentID Property
https://msdn.microsoft.com/en-us/library/bb207711.aspx
Comments
- Anonymous
November 28, 2008
PingBack from http://blog.a-foton.ru/index.php/2008/11/28/condition-is-not-valid-error-on-itemsfind-for-appointment-item-using-globalappointmentid-as-filter/