I have created some folders in SharePoint 2013 List and added some items into this. Now I want to fetch items from a specific folder using javascript or maybe REST. Please provide me with the solution.
Note its a custom SP list, not Library.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityYou can use Rest API to fetch all items from SharePoint list. Below is sample code to fetch all items from SharePoint list using Rest API.
function getListItems(webUrl, listTitle, viewXml) {
var url = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
var queryPayload = {
'query': {
'__metadata': {
'type': 'SP.CamlQuery'
},
'ViewXml': viewXml
}
};
return $.ajax({
url: url,
method: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(queryPayload),
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Accept": "application/json; odata=verbose"
}
});
}
function getAllFolderItems(webUrl, listTitle) {
var viewXml = '<View Scope="RecursiveAll"><Query><Where><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">1</Value></Eq></Where></Query></View>';
var data = getListItems(webUrl, listTitle, viewXml);
data.done(function(data) {
var items = data.d.results;
for (var i = 0; i < items.length; i++) {
console.log(items[i].Title);
}
}).fail(
function(error) {
console.log(JSON.stringify(error));
});
}
References : Retrieve folders and sub folders from document library by REST call
Add added one more line above CAML Query.
camlQuery.set_folderServerRelativeUrl("/Lists/PINCODE/FolderName");
camlQuery.set_viewXml("<View ><Query><Where><Eq><FieldRef" Name='columnName' />"<Value Type='Text'>" + SomeValue + "</Value></Eq></Where></Query></View > ");