I am trying to search for appointment on a shared calendar. The first step is I am saving the appointment in shared calendar with a custom property twMeetingId. This is working fine:
Outlook.AppointmentItem nurseAppointment = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Add();
nurseAppointment.UserProperties.Add("twMeetingId", Outlook.OlUserPropertyType.olText, false, 1);
nurseAppointment.UserProperties["twMeetingId"].Value = appointmentData.meetingId;
nurseAppointment.Save();
Then I am trying to find any appointments in the same shared calendar based on the custom property twMeetingId
var filter = $"@SQL =\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/twMeetingId/0000001f\" = '{appointmentData.meetingId}'";
Outlook.Items items = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Restrict(filter);
At this point I am receiving an error "Condition not valid". I have checked the meetingId value is correct in the filter. I have also tried to use Jet query as below but it also does not work:
nurseAppointment = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetSharedDefaultFolder(recepient, Outlook.OlDefaultFolders.olFolderCalendar).Items.Find(String.Format("[twMeetingId] = '{0}'", appointmentData.meetingId));
What am I missing here?
You have an erroneous space between @SQL
and =
. The following condition worked without error for me:
@SQL="http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/twMeetingId/0000001f" = 'test'
Also make sure appointmentData.meetingId
does not contain any characters that need to be encoded.