3

I am getting a query from list view by view.Query i got the following

<QUERY>
   <GroupBy Collapse="TRUE" GroupLimit="100"><FieldRef Name="AlertGrp" /></GroupBy>
   <OrderBy>
      <FieldRef Name="PriorityNoLink" Ascending="FALSE" />
      <FieldRef Name="match_time" Ascending="FALSE" />
   </OrderBy>
   <Where>
       <And>
           <And>
              <And>
                  <Neq><FieldRef Name="Category" /><Value Type="Text">ACH Alert</Value></Neq>
                  <Neq><FieldRef Name="Category" /><Value Type="Text">Check Fraud</Value></Neq>
              </And>
              <IsNull><FieldRef Name="Close_x0020_Reason" /></IsNull>
           </And>
           <Eq><FieldRef Name="AlertType" /><Value Type="Text">Alert</Value></Eq>
       </And>
    </Where>
</QUERY>

I want to add one more condition something like

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

I added after AlertType

<Eq><FieldRef Name="AlertType" /><Value Type="Text">Alert</Value></Eq>
</And>

and start tag <And> added in the beginning along with <And><And><And>

But showing wrong result. Kindly help me where I can add the new condition.

1
  • 1
    You are saying "wrong result". If the CAML query is not properly formatted (e.g., <And> tag in the wrong place) then you should get an error. If you don't get an error, what exactly is the wrong result?
    – CigarDoug
    Commented Jul 31, 2013 at 9:52

1 Answer 1

1
<Where>
    <And>
       <And>
           <And>
              <And>
                  <Neq><FieldRef Name="Category" /><Value Type="Text">ACH Alert</Value></Neq>
                  <Neq><FieldRef Name="Category" /><Value Type="Text">Check Fraud</Value></Neq>
              </And>
              <IsNull><FieldRef Name="Close_x0020_Reason" /></IsNull>
           </And>
           <Eq><FieldRef Name="AlertType" /><Value Type="Text">Alert</Value></Eq>
       </And>
       <Geq><FieldRef Name="Created" /><Value Type="DateTime"><Today OffsetDays="-5" />       </Value></Geq>
   </And>
</Where>

should work

5
  • He said "I added after AlertType ...". I was expecting his code to already look like your. ^_^
    – SPArcheon
    Commented Jul 31, 2013 at 9:15
  • Me too, but if it did, I also would expect it to work ;) Commented Jul 31, 2013 at 9:20
  • Thanks for answering. I tried this query in caml query builder it is showing result bt not the correct one. Am getting the first caml query from SpView.Query// but if i place the spview.Query value in the caml builder showing wrong data meantime in list it is showing perfect.
    – user18508
    Commented Jul 31, 2013 at 10:44
  • So I guess the problem is not the structure of the query, but more that the query is not correct for your needs Commented Jul 31, 2013 at 10:49
  • I would suggest that you use CAMLDesigner or U2U caml builder to build the query - then you can select the fields and generate the where-clause less error-prone. CAMLDesigner: sharepoint.biwug.be/CamlDesigner/CamlDesigner.zip Commented Aug 1, 2013 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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