My senario is like this:
In every site there is a list called Projects. I need to loop through each sub site and retrieve the last item from Projects list, and display them on a page in tabular fashion. So, the function should perform an aggregation of all last items retrieved from each list.
I have this bit, but I am not sure how to proceed any further:
$(document).ready(function(){
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/webs?$expand=Webs",
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data) {
for(i=0;i<data.d.results.length;i++){
console.log(data.d.results[i].Title;
$.ajax({
type: "GET",
url: data[i].__metadata.uri + "/lists/GetByTitle('Projects')/items?&$orderby=Id desc&$Top=1",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data) {
console.log(data);
for(i=0;i<data.d.results.length;i++){
console.log(" =>" + webUrl + " " +data.d.results[i].Title + " " + data.d.results[i].rcBudget);
}
}
});
}
},
error: function(rootsite) {console.log("error ");},
async: false
});
});
EDIT 1:
I have inserted another ajax call, but how do I get the web url together with the items queryed out of the ajax call and use them as a collection?
I need to display something like this:
WebUrl | Field 1 | Field 2 | Field 3 etc
web 1 | value 1 | value 2 | value 3
web 1 | value 1 | value 2 | value 3