I'm working with CAML Designer 2013 to create a query capable of returning all folders and subfolders within a SharePoint 2013 document library. I've gotten a working solution within the designer:
<ViewFields>
<FieldRef Name='FileLeafRef' />
<FieldRef Name='FileRef' />
</ViewFields>
<OrderBy>
<FieldRef Name='FileRef' />
</OrderBy>
<QueryOptions>
<ViewAttributes Scope='RecursiveAll' />
</QueryOptions>
<Where>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>1</Value>
</Eq>
</Where>
The resulting dataset gives me all folders at all levels, just as I expect. The problem becomes evident when I copy the CAML--as is--into my JavaScript. As soon as it leaves the Designer, my JavaScript only returns the top level folder information. Here's what the actual JS looks like:
$().SPServices({
operation: 'GetListItems',
async: false,
listName: 'Division Documents',
CAMLViewFields: '',
CAMLQuery: '<Query><ViewFields><FieldRef Name="FileLeafRef" /><FieldRef Name="FileRef" /></ViewFields><OrderBy><FieldRef Name="FileRef" /></OrderBy><QueryOptions><ViewAttributes Scope="RecursiveAll" /></QueryOptions><Where><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">1</Value></Eq></Where></Query>',
completefunc: function (xData, Status) {
var fileNames = [];
$(xData.responseXML).SPFilterNode('z:row').each(function() {
var fileName = $(this).attr('ows_FileLeafRef');
fileName = fileName.substring(fileName.indexOf(';#') + 2);
fileNames.push(fileName);
});
var myStuff = fileNames;
//$('#recentlyModified').append(htmlBuilder);
}
});
For example, given this structure in the library:
Folder 1
Subfolder 1.1
Subfolder 1.2
Folder 2
Subfolder 2.1
I get five results (Folder 1, Subfolder 1.1, Subfolder 1.2, Folder 2, Subfolder 2.1) in the designer, and only two (Folder 1 and Folder 2) in JavaScript.
My question for the community: do I need to add anything to the JS to get it to retrieve all levels? I've tried tons of alternatives to syntax, and nothing seems to work yet.