0

This is my first time using CAML Query.

I have a query builder which I can test with.

I'm trying to create a query that will look for a specific string of text in the "Title" column, and find the date "Created" less than equal to -180 days, and find "StatusPreSales" column equal to "Completed"

Title = Single Line Text Created = Date/Time StatusPreSales = Choice (DropDown)

<Query>
<Where>
    <Eq>
      <FieldRef Name="Title"></FieldRef>
      <Value Type="Text">Schust Engineering</Value>
    </Eq>
    <Leq>
      <FieldRef Name="Created" />
      <Value Type="DateTime">
      <Today OffsetDays="-180" />
      </Value>
    </Leq>
    <Eq>
      <FieldRef Name="StatusPreSales" />
      <Value Type="Choice">Completed</Value>
    </Eq>
</Where>
</Query>

This is the code I have but It doesn't seem to be filtering the date correctly or picking up the value of StatusPreSales column.

Does anyone know what i can do to fix my query?

2

It seems that you are missing <And> and also I think the date should be <Geq>.

Example of date CAML Query:

<Where>
<Geq>
    <FieldRef Name="Created" />
    <Value Type="DateTime">
        <Today OffsetDays="-180" />
    </Value>
</Geq>

The above code would get all items which were created in the last 180 days.

The full query should be:

<Query>
<Where>
 <And>
  <And>
    <Eq>
      <FieldRef Name="Title"></FieldRef>
      <Value Type="Text">Schust Engineering</Value>
    </Eq>
    <Geq>
      <FieldRef Name="Created" />
      <Value Type="DateTime">
      <Today OffsetDays="-180" />
      </Value>
    </Geq>
  </And>
    <Eq>
      <FieldRef Name="StatusPreSales" />
      <Value Type="Choice">Completed</Value>
    </Eq>
  </ANd>
 </Where>
</Query>
  • I'm using Leq to get items created before 180 days. Ultimately what I Plan to do is use the CAML Query in a PowerShell Script to recreate list items in another list that the query finds and then delete the items from the existing list. – zingwing Aug 12 '14 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.