0

I want to limit data returned by GetListItems of Lists.asmx service. Does anyone know why despite the query options below I get all items?

"<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
    "<listName>Documents</listName>"
    "<viewFields>"
        "<ViewFields>"
            "<FieldRef Name='ID'/>"
        "</ViewFields>"
    "</viewFields>"
    "<queryOptions>"
        "<QueryOptions>"
            "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>"
            "<ViewFieldsOnly>TRUE</ViewFieldsOnly>"
        "</QueryOptions>"
    "</queryOptions>"
"</GetListItems>"
1

GetListItems method accepts a parameter RowLimit to limit the number of items retrieved.

rowLimit - A string that specifies the number of items, or rows, to display on a page before paging begins. If supplied, the value of this parameter overrides the row limit set in the view specified by the viewName parameter or the row limit set in the default view for the list.

"<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
    "<listName>Documents</listName>"
    "<viewFields>"
        "<ViewFields>"
            "<FieldRef Name='ID'/>"
        "</ViewFields>"
    "</viewFields>"
    "<queryOptions>"
        "<QueryOptions>"
            "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>"
            "<ViewFieldsOnly>TRUE</ViewFieldsOnly>"
        "</QueryOptions>"
    "</queryOptions>"
    "<rowLimit">
        "10"
    "</rowLimit>"
"</GetListItems>"
  • Row Limit only take care of the rows. While ViewFields will limit the fields. – Amal Hashim Mar 26 '15 at 14:46
  • How rowLimit should make the server return only those fields listed in <ViewFieldsOnly>? My result should contain all items from query (if I use them). The task is to show only ID for each item (row). – andrii Mar 26 '15 at 14:47
  • See this thread stackoverflow.com/questions/9889900/… – Amal Hashim Mar 26 '15 at 14:50
  • 1
    I have tried <rowLimit>1</rowLimit> and (as expected) it limits rows but not columns – andrii Mar 26 '15 at 15:19
  • Please read the link i provided. ROWLIMIT only limits number of ROWS and not COLUMNS. For limiting columns you need to use <ViewFieldsOnly>.. but as per my above comment, the link says its a bug.. – Amal Hashim Mar 26 '15 at 15:21
0

Add the following line after </viewFields> or </queryOptions>:

<rowLimit>1</rowLimit>

Keep in mind that it's case sensitive.

Your query should look like this:

"<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">" "<listName>Documents</listName>" "<viewFields>" "<ViewFields>" "<FieldRef Name='ID'/>" "</ViewFields>" "</viewFields>" "<rowLimit>1</rowLimit>" "<queryOptions>" "<QueryOptions>" "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" "<ViewFieldsOnly>TRUE</ViewFieldsOnly>" "</QueryOptions>" "</queryOptions>" "</GetListItems>"

More information on GetListItems method: https://msdn.microsoft.com/en-us/library/dd586530%28v=office.11%29.aspx

  • 1
    look at my comment to previous post – andrii Mar 26 '15 at 14:48

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.