Need help with CAML from JavaScript to retreive all items from a SharePoint Message Board

I am using JavaScript to invoke the GetListItems method of the SP webservice and handing in the following CAML:

    var CAML = "<Query>"
            + "<ViewAttributes Scope=\"Recursive\" />"
            + "<Where>"
            + "<Or>"
            + "<Eq>"
            + "<FieldRef Name=\"ID\"/>"
            + "<Value Type=\"Counter\">" + id + "</Value>"
            + "</Eq>"
            + "<Eq>"
            + "<FieldRef Name=\"ParentFolderId\" />"
            + "<Value Type=\"Integer\">" + id + "</Value>"
            + "</Eq>"
            + "</Or>"
            + "</Where>"
            + "</Query>";

    var fieldinfo = "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Body' /><FieldRef Name='CorrectBodyToShow' /><FieldRef Name='Created' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='PersonalImage' /><FieldRef Name='DiscussionLastUpdated' /></ViewFields>"

And I only receive the top level item back...the Discussion Type item. There are 2 Message Type items related to the ParentFolderId of 1 but they do not get returned.

As an aside, if I run the CAML in the U2U tool it DOES return the entire Discussion and two Messages.



You need to set a property called Scope=Recursive. You've done this in your CAML but in the wrong place.

If you are using the object model then you would use

query.ViewAttributes = "Scope=\"Recursive\"";

However you're using the web service. In your example you've put ViewAttributes as a child of the Query node - but this is incorrect.

It should be part of the queryOptions paramater of GetListItems

So in addition to your code above you would nee

   var queryOptions = "<QueryOptions>" +
                         "<ViewAttributes Scope='Recursive' />" +

Then inside your javascript wrapper you would call it something like this (NOTE - this obviously won't work as is but you get the idea)

listService.GetListItems("List_Name", null,
                         CAML, fieldinfo , null, 
                         queryOptions, null);

the recursive feature is part of the query options object not the view options object in the web service

I have a hunch that you need to set the recusion in the SPQuery object, rather than in the query caml, eg:

qry.ExpandRecurrence = true

but I might be wrong :) I found that some sorting did not always work either.

Need Your Help

How to setup a ListView that get its data from a server

android listview layout

I've been trying to find a tutorial of how to create a ListView that get its data from a server dynamically as it's scrolled. I have not been able to find complete documents of how to do this. Only

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.