开发者

CAML from JavaScript to retrieve all items from a SharePoint Message Board

开发者 https://www.devze.com 2022-12-21 14:40 出处:网络
I am using JavaScript to invoke the GetListItems method of the SP webservice and handing in the following CAML:

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>"
开发者_StackOverflow社区            + "</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.


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


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);


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号