0

Trying to get event items from a list, I issue a CAML query that only returns a small number of items (about 17). When I set the List View Threshold at 10000 everything works fine, but when I set the LVT at 5000, I get a "Exceeded List View Threshold set by the administrator" error. My CAML query is pretty simple:

<Where>
<And>
    <DateRangesOverlap>
        <FieldRef Name="EventDate" />
        <FieldRef Name="EndDate" />
        <FieldRef Name="RecurrenceID" />
        <Value Type="DateTime">
            <Now />
        </Value>
    </DateRangesOverlap>
    <And>
        <BeginsWith>
            <FieldRef Name="Place" />
            <Value Type="Text">Boston</Value>
        </BeginsWith>
        <Or>
            <Eq>
                <FieldRef Name="Status" />
                <Value Type="Text">Status1</Value>
            </Eq>
            <Eq>
                <FieldRef Name="Status" />
                <Value Type="Text">Status2</Value>
            </Eq>
        </Or>
    </And>
</And>

Can anyone explain why this may be happening? Is is because when expanding recurrences SP actually runs a separate query that result in the LVT being exceeded? Any suggestions to restructure the query would be great, but I do need to look at all occurrences of recurring events (not just the master items).

Alex Ziskind
  • 140
  • 1
  • 12
  • How many events does the list contain? I don't think it is a matter of how much items the query returns, but about how many events the list holds. – Mathieu Nov 30 '12 at 23:58
  • The list contains more than 5000 items. The reason to limit CAML queries is so they don't select more than LVT number of items. Your answer suggests that if any list has more than LVT number of items, then all CAML queries will fail - which is not the case. Please try again. – Alex Ziskind Dec 01 '12 at 14:39

1 Answers1

2

In case anyone is interested, I've managed to play around with the Query and find out how to avoid hitting the threshold. What I did was simply change the order of the query elements so that my indexed fields were listed first and the DateRangesOverlap node was listed last. Here is the result that works:

    <Where>
<And>
    <BeginsWith>
        <FieldRef Name="Place" />
        <Value Type="Text">Boston</Value>
    </BeginsWith>
    <And>
        <Or>
            <Eq>
                <FieldRef Name="Status" />
                <Value Type="Text">Status1</Value>
            </Eq>
            <Eq>
                <FieldRef Name="Status" />
                <Value Type="Text">Status2</Value>
            </Eq>
        </Or>
        <DateRangesOverlap>
            <FieldRef Name="EventDate" />
            <FieldRef Name="EndDate" />
            <FieldRef Name="RecurrenceID" />
            <Value Type="DateTime">
                <Now />
            </Value>
        </DateRangesOverlap>
    </And>
</And>
</Where>
Alex Ziskind
  • 140
  • 1
  • 12