Restrict Function Not Working Properly with Recurring Items

Amir 11 Reputation points
2022-07-18T00:08:22.957+00:00

It seems that the Restrict function is not working properly with Calendar items. Specifically, when a filter is passed to return calendar items within a specified time, then recurring meetings are returned do not occur between the times specified in the filter.

Problem can be reproduced as follows:

Calendar = outlook_mapi.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
all_messages = calendar.Items
all_messages.IncludeRecurrences = True
all_messages = all_messages.Restrict(f"[Start] >= '{date_str} 12:00AM' And [Start] <= '{date_str} 11:59PM'")
where date_str =f"{month}/{day}/{year}" and month/day/year is the particular date that we want to read the calendar

This then returns all recurring meetings in a user's calendar, irrespective of whether they occur on the specified time above or not.

Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
{count} votes

2 answers

Sort by: Most helpful
  1. Li, Xiangrui 6 Reputation points
    2022-10-18T21:54:19.31+00:00

    I found a solution for the issue, that is to sort the items then Restrict, and maybe Restrict again. Here is the pseudo code:

    Calendar = outlook_mapi.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
    myItems = calendar.Items(filter) # use your filter
    myItems.IncludeRecurrences = True # apply this to my items, not all items
    myItems.Sort("[Start]")
    myItems= myItems.Restrict(filter)

    Cheers!

    1 person found this answer helpful.

  2. Amir Gholami 1 Reputation point
    2022-07-26T23:39:17.387+00:00

    @Carlos Solís Salazar
    Hey Carlos,

    Can you please forward this question to one of the engineers in Outlook team? They seem to have merged a code that has broken the functionality of searching recurring items.

    Thanks,

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.