1

I am having a list with 40 columns and need to fetch only 10 fields in a batch of 4. how to achieve this. Can someone provide me caml query. I prepared below caml to fetch 2 columns please let me know if this is correct and what addition i have to do. Thanks.

query.Viewfields= "<FieldRef name='column1'/><FieldRef name='column2'/>";
1

Hi regarding to caml query for viewfields you can use below

SPQuery query = new SPQuery();
           query.Query = string.Concat(
                          "<Where><Eq>",
                             "<FieldRef Name='Status'/>",
                             "<Value Type='CHOICE'>Not Started</Value>",
                          "</Eq></Where>",
                          "<OrderBy>",
                             "<FieldRef Name='DueDate' Ascending='TRUE' />",
                             "<FieldRef Name=’Priority’ Ascending='TRUE' />", 
                          "</OrderBy>");                    

           query.ViewFields = string.Concat(
                               "<FieldRef Name='AssignedTo' />",
                               "<FieldRef Name='LinkTitle' />",
                               "<FieldRef Name='DueDate' />",
                               "<FieldRef Name='Priority' />");

           query.ViewFieldsOnly = true; // Fetch only the data that we need.

Here is reference to it

1

try this it works.

 var soapEnv =
        "<soapenv:Envelope 
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>Test</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
<FieldRef Name='ID' /> \
               <FieldRef Name='Modified' /> \
             <FieldRef Name='lastname' /> \
             <FieldRef Name='Firstname' /> \
             <FieldRef Name='Phone' /> \
                       </ViewFields> \
  </viewFields> \
  <query> \
   <Query> \
<Where> \
<Or> \
<Contains> \
     <FieldRef Name='Title' /> \
     <Value Type='Text'>"+qry+"</Value> \
</Contains> \
<Or> \
<Contains> \
     <FieldRef Name='lastname' /> \
     <Value Type='Text'>"+qry+"</Value> \
</Contains> \
<Or> \
<Contains> \
     <FieldRef Name='Firstname' /> \
     <Value Type='Text'>"+qry+"</Value> \
  </Contains> \
           <Contains> \
           <FieldRef Name='Phone' /> \
              <Value Type='Text'>"+qry+"</Value> \
              </Contains> \
        </Or> \
     </Or> \
  </Or> \
  </Where> \
</Query> \
  </query> \
   </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";       
0
  SPQuery query = new SPQuery();
               query.Query = string.Concat(
                              "<Where><Eq>",
                                 "<FieldRef Name='col1'/>",
                                 "<Value Type='CHOICE'>Not Started</Value>",
                              "</Eq></Where>",
                              "<OrderBy>",
                                 "<FieldRef Name='col2' Ascending='TRUE' />",
                                 "<FieldRef Name=’col3’ Ascending='TRUE' />", 
                              "</OrderBy>");                    

               query.ViewFields = string.Concat(
                                   "<FieldRef Name='col1' />",
                                   "<FieldRef Name='col2' />",
                                   "<FieldRef Name='col3' />",
                                   "<FieldRef Name='col4' />");

               query.ViewFieldsOnly = true; // Fetch only the data that we need.

Need to update ViewFieldsOnly to true.

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.