Dear All,
I am retrieving the list items with below from SharePoint online using JSOM for Out of Box,
But the performance for loading the data is very slow . And I am willing to use PortalSiteMapProvider to fetch the data which will be giving better performance .
Can any one please help me in knowing how can we make it.
<script src=”//code.jquery.com/jquery-1.10.2.js”></script>
<script>
//alert(‘start script’);
var listItems;// The list of retrieved items.
var camlQuery;// For paging, reuse the same query object.
var oList;// The list from which to retrieve items.
var clientContext;
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, “sp.js”);
function retrieveListItems(){
//alert(‘enters function’);
clientContext = new SP.ClientContext.get_current();
oList = clientContext.get_web().get_lists().getByTitle(‘ScorecardSiqqidNew’);
camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(“<View><Query><OrderBy><FieldRef Name=’Title’ Ascending=’TRUE’ /></OrderBy></Query></View>”);
camlQuery.RowLimit = 101;
this.listItems = oList.getItems(camlQuery);
clientContext.load(listItems);
clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed) );
}
function onQuerySucceeded(){
var listItemInfo = ”;
var listEnumerator = listItems.getEnumerator();
while (listEnumerator.moveNext()) {
var oListItem = listEnumerator.get_current();
listItemInfo +=’ <strong>Table top Sessions:</strong> ‘ + oListItem.get_item(‘Title’) +’ <br />’;
}
$(‘#divHelloWorld’).html(listItemInfo);
var position = listItems.get_listItemCollectionPosition();
if (position != null) {
query.set_listItemCollectionPosition(position);
listItems = targetList.getItems(query);
clientContext.load(listItems);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
function onQueryFailed(sender, args){
alert(‘Request failed. ‘ + args.get_message() +’n’ + args.get_stackTrace());
}
</script>
<p id=”divHelloWorld”>Hello World!</p>
Try using batch requests.
<code> List<ListItem> items = new List<ListItem>();
using (ClientContext context = SharePointContext.GetSharePointContext()) {
List list = context.Web.Lists.GetByTitle("ListName");
int rowLimit = 100;
ListItemCollectionPosition position = null;
string viewXml = string.Format(@"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='FieldName' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>
</Query>
<ViewFields>
<FieldRef Name='Title' />
</ViewFields>
<RowLimit>{1}</RowLimit>
</View>", FieldName, rowLimit);
var camlQuery = new CamlQuery();
camlQuery.ViewXml = viewXml;
do {
ListItemCollection listItems = null;
if (position != null) {
camlQuery.ListItemCollectionPosition = position;
}
listItems = list.GetItems(camlQuery);
context.Load(listItems);
Task contextTask = context.ExecuteQueryAsync();
await Task.WhenAll(contextTask);
position = listItems.ListItemCollectionPosition;
items.AddRange(listItems.ToList());
}
while (position != null);
}
return items;
}</code>
