This project has moved and is read-only. For the latest updates, please go here.

combine GetListItems + GetListAndview

Aug 25, 2011 at 2:11 AM

Are there any operations that combine those two such that I get the viewfields for a view, the field definitions and the list data?

Trying to find a way to only make one ajax request instead of two.

Aug 25, 2011 at 3:13 AM

Reading over the documentation, it's possible to pass a viewName as an option.  Here's a good post I just wrote describing how to use the documentation:

There's one tidbit I left out from that post.  Sometimes it's necessary to click on the MSDN documentation link and read more about that particular method.  Here is an excerpt from GetListItems:



A string that contains the GUID for the view surrounded by curly braces ({}), which determines the view to use for the default view attributes represented by the queryviewFields, and rowLimit parameters. If this parameter contains an empty string, the default view is used. If the view GUID is supplied, the value of the queryviewFields, or rowLimit parameter overrides the equivalent setting within the view. For example, if the view specified by the viewFields parameter has a row limit of 100 rows but the rowLimit parameter contains 1000, then 1,000 rows are returned in the response. 


This seems to read exactly what you are asking for.  You'll need to get the GUID of the view and add that to your SPServices call.  

Post back if you need more info



Aug 25, 2011 at 4:19 AM


If you want to get at the field definitions *and* the list item data, I don't think you can avoid two calls. It really depends on what you actually need to do from there.


Aug 25, 2011 at 5:12 PM

I'm writing a script that can be used to show an SP List as a table with table and column filters. So you'd put something like so in your page and then my script would process it.


<div class="nacho_table" webURL="optional" listName="list name" viewDisplayName="optional"></div>


The webURL and viewDisplayName attributes are optional. If you provide a viewDisplayName my script will find the viewGUID. So right now my script does these operations, in this order:

  1. operation: WebUrlFromPageUrl to get the webURL if not provided (needed to build title URLs later)
  2. operation: GetViewCollection to determine the viewName if viewDisplayName was provided, else default view is used
  3. operation: GetFormCollection to determine the forms (mainly the DisplayForm) used to build title URLs later)
  4. operation: GetListAndView to:
    1. determine the columns/fields shown in a view
    2. figure out what needs to be done to 'fix' data for that field type (e.g. for a date field the value needs to be converted to a date object, or for a number with % and 2 decimal places necessary formatting has to be applied to the value, or for title columns the URL of the display form needs to be added)
  5. operation: GetListItems to iterate through all the rows in the list and build the necessary table
    1. this function uses the information returned from Step 4 to "fix" the data

What I am trying to do is combine as many calls as I can to speed everything up. Does that make sense?

Aug 26, 2011 at 7:22 PM

That's ambitious!

I think you'll find that there's no way around the multiple calls. Web Services calls are *extremely* efficient. so you might be surprised how fast they are. Often the first one hangs for a bit, but then the rest fly by.


Aug 27, 2011 at 4:32 AM

Yeah. I've actually figured out how to make some of the calls at the same time. Thanks for your help.