views:

297

answers:

3

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 thread...one Discussion and two Messages.

John

A: 

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.

Jonesie
I think you're on to something...a previous consultant created a javascript wrapper that we're calling to roll the CAML into a SOAP envelope, would you have any idea where to set ExpandRecurrence?
John Weaver
Not sure why you need soap. Can you cerate an aspx on the server rather than using he web services? If so the you can use the SPQuery object in that. If not then you mave to code the recursive functionality in js.
Jonesie
Oh, theres a comment on this blog post that might help: http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1765
Jonesie
Think you've taken a wrong turn - ExpandRecurrances is to do with Event lists (e.g. Calendar lists) and recurring events, not foldershttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.expandrecurrence.aspx
Ryan
+1  A: 

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

Brian Brinley
A: 

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' />" +
                      "</QueryOptions>";

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);
Ryan
Since the wrapper is rolling everything into a SOAP envelope that's handed to the web service should I just add the new query options as a root level node in the SOAP body?
John Weaver
I would think its something like that. The queryoptions is a separate param when calling the .GetListItems web service and this will be put somewhere in the SOAP request but I've never worked with raw SOAP requests before (VS does all the plumbing for you) so not totally sure.
Ryan
Your rely was the soulution! It is a seperate node under the <GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"> root...the part that I was missing is that they QueryOptions need to be "double wrapped" to work just like the Query node. <queryOptions> <QueryOptions> <ViewAttributes Scope='Recursive' /> </QueryOptions> </queryOptions>Thanks much Ryan!
John Weaver