1
Vote

CamlBuilder.FromXml().ModifyWhere() not working correctly

description

example:
var q = CamlBuilder.FromXml('<View><Query><Where><IsNotNull><FieldRef Name="Title" /></IsNotNull></Where><OrderBy><FieldRef Name="Title" /></OrderBy></Query><RowLimit Paged="TRUE">30</RowLimit><ViewFields><FieldRef Name="ID" /><FieldRef Name="LinkTitle" /></ViewFields></View>');
var result = q.ModifyWhere().AppendAnd().TextField("Title").Contains("test").ToString();

result :

<View>
<Query>
  <OrderBy>
     <FieldRef Name="Title" />
  </OrderBy>
  <RowLimit Paged="TRUE">30</RowLimit>
  <ViewFields>
     <FieldRef Name="ID" />
     <FieldRef Name="LinkTitle" />
  </ViewFields>
  <Where>
     <And>
        <IsNotNull>
           <FieldRef Name="Title" />
        </IsNotNull>
        <Contains>
           <FieldRef Name="Title" />
           <Value Type="Text">test</Value>
        </Contains>
     </And>
  </Where>
</Query>
</View>

Instead :
<View>
<Query>
  <OrderBy>
     <FieldRef Name="Title" />
  </OrderBy>
  <Where>
     <And>
        <IsNotNull>
           <FieldRef Name="Title" />
        </IsNotNull>
        <Contains>
           <FieldRef Name="Title" />
           <Value Type="Text">test</Value>
        </Contains>
     </And>
  </Where>
</Query>
  <RowLimit Paged="TRUE">30</RowLimit>
  <ViewFields>
     <FieldRef Name="ID" />
     <FieldRef Name="LinkTitle" />
  </ViewFields>     
</View>

comments

rpohomenko wrote Jan 24 at 9:10 AM

PS: need to check if Where is empty , so not needed to append And or Or