I am making use of an SP.Service to retrieve the items of a particular list (Site Assets). I know the way to retrieve all the items under the list: using a caml query and the function createAllItemsQuery(). However I just need to retrieve the immediate child items.
Here is my actual structure of Site Assets:
SiteAssets
Folder1
Folder1.1
Folder1.2
Folder2
Folder2.1
Etc...
So at the moment I am retrieving absolutely all the items bellow SiteAssets, and I wish only to retrieve Folder1, Folder2, which are the immediate child items of the lists.
Following is the code that I am using:
ExecuteOrDelayUntilScriptLoaded(retrieveAllListProperties, "sp.js");
function retrieveAllListProperties()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Site Assets');
var query = SP.CamlQuery.createAllItemsQuery(); <-------// The caml query I am using
allItems = list.getItems(query);
context.load(allItems, 'Include(DisplayName,Id)'); <-------// Loading the context of the items
context.executeQueryAsync(Function.createDelegate(this, this.viewSuccess), Function.createDelegate(this, this.failed));
}
function viewSuccess()
{
var TextFiled = "";
var ListEnumerator = allItems.getEnumerator(); <-------// Getting all the items, I just need the immediate child items, not sub-child items
while (ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
var title = currentItem.get_displayName();
var id = currentItem.get_id().toString();
console.log("Title: " + title + " Id: " + id); <-------// I am printing at the moment the name of the child and it's id
}
}
function failed(sender, args)
{
console.log('failed. Message:' + args.get_message());
}
Is it posible to retrieve only the immediate child items? Can someone help me here?