3

I'm fighting with the Caml Query which returns zero items:

<View>
    <Query>
        <Where>
            <And>
                <Eq>
                    <FieldRef Name="Dokumenttyp"/>
                    <Value Type="Text">Fahrtspesen</Value>
                </Eq>
                <And>
                    <Geq>
                        <FieldRef Name="ExportiertAm"/>
                        <Value Type="DateTime">2017-08-12</Value>
                    </Geq>
                    <Lt>
                        <FieldRef Name="ExportiertAm"/>
                        <Value Type="DateTime">2017-08-13</Value>
                    </Lt>
                </And>
            </And>
        </Where>
    </Query>
</View>

What I do not understand, the following two return something. The first returns many items (one of these is the one with ID 290) and the second one returns two items (the 290 and the 291).

<View>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name="Dokumenttyp"/>
                <Value Type="Text">Fahrtspesen</Value>
            </Eq>
        </Where>
    </Query>
</View>

<View>
    <Query>
        <Where>
            <And>
                <Geq>
                    <FieldRef Name="ExportiertAm"/>
                    <Value Type="DateTime">2017-08-12</Value>
                </Geq>
                <Lt>
                    <FieldRef Name="ExportiertAm"/>
                    <Value Type="DateTime">2017-08-13</Value>
                </Lt>
            </And>
        </Where>
    </Query>
</View>

Based on the results of the latter two, shouldn't the first one return something?

4
  • Is there any error dialog show up when you use the query? Commented Aug 29, 2017 at 6:59
  • No errors, simply zero results. Commented Aug 29, 2017 at 7:28
  • I don't see any error in your query. Your combined query should return one item that has ID 290. Commented Aug 29, 2017 at 9:51
  • please share your code that you are using to fetch the data. Commented Aug 29, 2017 at 9:53

2 Answers 2

1

While CAML works it's logic '2 at a time', I've found that having an AND/OR group at the end doesn't work sometimes, even though it logically should. Since you've got all ANDs, maybe try a bit of rearranging. It makes no sense, I know. Also, another thing I've tried is to get rid of your code completely and retype it. There could be an 'invisible' character or extra space that is causing a problem without reporting an error.

         <And>
            <And>
                <Geq>
                    <FieldRef Name="ExportiertAm"/>
                    <Value Type="DateTime">2017-08-12</Value>
                </Geq>
                <Lt>
                    <FieldRef Name="ExportiertAm"/>
                    <Value Type="DateTime">2017-08-13</Value>
                </Lt>
            </And>
            <Eq>
                <FieldRef Name="Dokumenttyp"/>
                <Value Type="Text">Fahrtspesen</Value>
            </Eq>
        </And>
0

You can use U2U caml query builder for framing the queryenter image description here

1
  • This is not an answer to my question. Commented Aug 30, 2017 at 6:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.