5

Note: This question is similar to an existing, unanswered question (CAML OrderBy for SharePoint Recurring Calendar Event).

How can I use the Lists.asmx web service to retrieve recurring events that occur today or later?

I am providing the <CalendarDate>2019-06-25T15:55:04.108Z</CalendarDate> parameter when sending the request to the /_vti_bin/Lists.asmx web service, yet I'm still receiving events from the past (as shown in the screenshot below)!

This is the XML response (screenshot). Notice how the event dates are before today even though "CalendarDate" is specified as "2019-06-25":

enter image description here

This is the XML payload sent with the request:

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
  <soap:Body>
    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
      <listName>{ my list GUID }</listName>
      <query>
        <Query>
          <OrderBy>
            <FieldRef Ascending='TRUE' Name='EventDate' />
          </OrderBy>
          <Where>
            <And>
              <Eq>
                <FieldRef Name="fRecurrence" />
                <Value Type="Boolean">1</Value>
              </Eq>
              <DateRangesOverlap>
                <FieldRef Name="EventDate" />
                <FieldRef Name="EndDate" />
                <FieldRef Name="RecurrenceID" />
                <Value Type='DateTime'>
                  <Year/>
                </Value>
              </DateRangesOverlap>
            </And>
          </Where>
        </Query>
      </query>
      <viewFields>
        <ViewFields>
          <FieldRef Name="Category" />
          <FieldRef Name="Location" />
        </ViewFields>
      </viewFields>
      <queryOptions>
        <QueryOptions>
          <ViewAttributes Scope="RecursiveAll" />
          <RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>
          <DateInUtc>TRUE</DateInUtc>
          <ExpandRecurrence>TRUE</ExpandRecurrence>
          <CalendarDate>2019-06-25T15:55:04.108Z</CalendarDate>
          <RecurrenceOrderBy>TRUE</RecurrenceOrderBy>
        </QueryOptions>
      </queryOptions>
      <rowLimit>20</rowLimit>
    </GetListItems>
  </soap:Body>
</soap:Envelope>

Edit: The following is an example of an event that is not being returned by the query above.

enter image description here

user1477388
  • 20,790
  • 32
  • 144
  • 264

1 Answers1

1

Year does not honour the CalendarDate property - it returns previous events that happened within a year from current date and future events a year from current date.

Use <Value Type='DateTime'><Now /></Value> in the DateRangesOverlap and remove the CalendarDate to retrieve recurring events that occur today or later

Fraser
  • 15,275
  • 8
  • 53
  • 104
  • Hi, Fraser, I've made the changes but I am still seeing events from back in April of 2019. Is there anything else I can try? Please see my edit for any details you might find relevant. – user1477388 Jul 08 '19 at 17:48
  • 1
    Nevermind, your example works! I noticed the `EndDate` is several months out for those events. The only other issue I am seeing is that only 9 items are returned, yet there are many events that run weekly (i.e. every Wednesday) that aren't present. I have added `100` but still it returns only 9. Do you know of anything I can try to resolve this or should I post a new question? – user1477388 Jul 08 '19 at 18:51
  • 1
    Hmmm - try removing the `rowLimit` completely...at a guess your other results are paged - or else there is something off with how they are set up. Without seeing the actual event data it's pretty hard to say, sorry. – Fraser Jul 08 '19 at 19:21
  • Thanks for the info. I tried removing `rowLimit` but it still returns just 9 results. I edited the question with an example of an event that does not get returned by the query. Is there any other information you might need to help understand why events like this are not being returned by the API? – user1477388 Jul 08 '19 at 19:56
  • How are the events created, via the UI or programatically? A common issue when creating recurring events is missing the `UID` (which should be set to `Guid.NewGuid()`) - also ensuring that the `EventType` is set to `1` – Fraser Jul 08 '19 at 20:57
  • All events are created via the UI, but to add to the confusion, other events within the same series are showing. For example, I am getting the events on 4/10 and 7/13, but not 7/17! Any ideas? I am not sure how to check the `EventType` to confirm whether it is set to `1`. – user1477388 Jul 08 '19 at 21:06
  • Hmm that is v.odd...could you try removing `RecurrenceOrderBy` from the `QueryOptions`. Also were the events in question created recently - or have they been in place for a long time? – Fraser Jul 09 '19 at 10:04
  • Right! The events were created a few months ago as shown in the screenshot added to the question. Removing `RecurrenceOrderBy` seems to have no effect. When I change `` to `2019-07-09T13:52:28.079Z` the API returns 19 items; however, it still seems to be missing several of the future events i.e. the 7/17/19 event shown in the screenshot above, yet it shows earlier events from the same series. – user1477388 Jul 09 '19 at 14:29
  • 1
    It is super hard to say what is happening here...could you try adding `fRecurrence` to the `ViewFields` to see if that resolves it? Also you might get better support here https://sharepoint.stackexchange.com/ - sorry I can't really help further without seeing the actual event data/calendars myself :( – Fraser Jul 09 '19 at 22:11