<script type="text/javascript" language="javascript"> ExecuteOrDelayUntilScriptLoaded(RetrieveListItems, "sp.js"); var clientContext = null; var spWebobj = null; var spListobj = null; var liCount; var items; var listItemInfo = ''; function RetrieveListItems() { clientContext = new SP.ClientContext.get_current(); this.site = clientContext.get_web(); this.webSubSites = site.get_webs(); clientContext.load(this.webSubSites, 'Include(Title, ServerRelativeUrl)'); clientContext.executeQueryAsync(Function.createDelegate(this, this.onLoadSubWebs), Function.createDelegate(this, this.onQueryFailed)); } function onLoadSubWebs(sender, args) { items = []; for (var x = 0; x < this.webSubSites.get_count(); x++) { web = this.webSubSites.itemAt(x); var siteUrl = web.get_serverRelativeUrl(); spListobj = web.get_lists().getByTitle("Tasks"); var spCamlQuery = new SP.CamlQuery(); var spViewXML = '<View><Query><Where><And><Leq><FieldRef Name="DueDate"/><Value Type="DateTime"><Today OffsetDays="-3"/></Value></Leq><Neq><FieldRef Name="Status"/><Value Type="Text">Completed</Value></Neq></And></Where></Query></View>'; spCamlQuery.set_viewXml(spViewXML); var spListobjItems = spListobj.getItems(spCamlQuery); var itemDetails = new Object; itemDetails.ListItems = spListobjItems; itemDetails.WebTitle = web.get_title(); itemDetails.TaskListOverDueViewURL = siteUrl + '/Lists/Tasks/'; items.push(itemDetails); clientContext.load(spListobjItems, 'Include(Id, FileDirRef)'); } clientContext.executeQueryAsync(Function.createDelegate(this, this.onLoadTaskDetails), Function.createDelegate(this, this.onQueryFailed)); } function onLoadTaskDetails(sender, args) { var htmlGetTitle = "<ul>"; var htmlGetCount = "<ul>"; for (var x = 0; x < items.length; x++) { var itemDetails = items[x]; htmlGetCount += "<li>" + itemDetails.ListItems.get_count() + "</li>"; htmlGetTitle += "<li> <a href='" + itemDetails.TaskListOverDueViewURL + " ' target=_blank'> <u>" + itemDetails.WebTitle + "</u> </a> </li>"; } document.getElementById('divSiteCount').innerHTML = htmlGetCount; document.getElementById('divSiteTitle').innerHTML = htmlGetTitle; } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script> <table> <tr> <th>Project</th> <th>Exceptions</th> </tr> <tr id="divSiteListings"> <td> <div id="divSiteTitle"></div></td> <td> <div id="divSiteCount"></div></td> </tr> </table>
sharepoint 2010, sharepoint 2013 , sharepoint 2016 , office 365
Monday, October 19, 2015
Get all List items from Subsites using ECMAScript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment