Search for list items by Created Date using caml

Hi all,

I'm trying to find list items with specific attributes using caml.

I created a caml query that uses Last_x0020_Modified and File_x0020_Size for searching items.

then i tried adding Created and Created_x0020_Date both either as Lookup or as DateTime to the caml.

But since i added Created/Created_x0020_Date my query fails with 500 Internal Server Error.

Can someone tell me what I'm doing wrong?

here is my complete Entity I'm sending to SharePoint 2013:

{'query' : { '__metadata': { 'type': 'SP.CamlQuery' }, 'ViewXml': '<View Scope="Recursive">
  <Query>
    <Where>
      <And>
        <Leq>
          <FieldRef Name="Last_x0020_Modified" />
          <Value Type="Lookup">2015-02-25T10:10:03</Value>
        </Leq>
        <Geq>
          <FieldRef Name="File_x0020_Size" />
          <Value Type="Lookup">1</Value>
        </Geq>
        <Leq>
          <FieldRef Name="Created" />
          <Value Type="DateTime">2015-02-25T10:10:03</Value>
        </Leq>
        <Eq>
          <FieldRef Name="FileDirRef" />
          <Value Type="Text">/sites/DennisDevSite/alib/Ordner1</Value>
        </Eq>
      </And>
    </Where>
  </Query>
</View>' } }

Thx in advance


Dennis

February 25th, 2015 4:30am

Try appending "Z" to DateTime. Change 

<Value Type="DateTime">2015-02-25T10:10:03</Value>

to

<Value Type="DateTime">2015-02-25T10:10:03Z</Value>
Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 5:03am

Hi again,

thx for that hint NadeemYousuf,

i  have tried it.

But now I have a new situation.

I tried using only two conditions in the </And> Tag and then it worked.

Adding a third one gave me the 500 internal Server Error again.

So it seems the problem is that i am trying to use 3 conditions in my </And>

So it seems now I have to find out, how to connect three conditions ..

Thx

Dennis

Edit:

Now I have found this blog

https://sharepointsharpener.wordpress.com/2008/06/27/several-ands-in-a-caml-query/

and will try it by nesting the </And> - Tags


February 25th, 2015 5:29am

Datetime values shall be in following format "yyyy-MM-ddTHH:mm:ssZ". Additionally, you may want to add "IncludeTimeValue" as in:

<Value Type="DateTime" IncludeTimeValue="FALSE"><formatted date value></Value>

SharePoint Object Model has SPUtility.CreateISO8601DateTimeFromSystemDateTime function to convert it to appropriate format.


Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 5:31am

Hi,

Here is an example showing use of three conditions:

<Query>
   <Where>
      <And>
         <Eq>
            <FieldRef Name='Title' />
            <Value Type='Text'>x</Value>
         </Eq>
         <And>
            <Eq>
               <FieldRef Name='Location' />
               <Value Type='Text'>y</Value>
            </Eq>
            <Eq>
               <FieldRef Name='Comments' />
               <Value Type='Note'>z</Value>
            </Eq>
         </And>
      </And>
   </Where>
</Query>

I will suggest you to use a CAML Query builder tool. It makes working with CAML quires very easy.

http://www.u2u.be/Software

February 25th, 2015 6:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics