1

I have written some javascript that generates a link with filters for a list of items. It has a couple of drop downs to choose certain filter values. This is all good until the list reaches 5k items. Now i cant apply the filter because it has reached the list view threshold even thought the list after the filter is applied is below the threshold.

How do i handle loading only the items that pass the filter criteria, instead of loading all items and then apply the filter?

I can do this in the view settings under filtering, but i dont want to create a new view for each possibility for my drop downs

0

Try this, it's developed using CSOM, u can change it as per your script. filteritems variable stores the filtered result.

IEnumerable<Microsoft.SharePoint.Client.ListItem> filteritems = null;
ListItemCollectionPosition position = null;
var page = 1;
List<Microsoft.SharePoint.Client.ListItem> items = new List<Microsoft.SharePoint.Client.ListItem>();

try
{
    do
    {
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = @"<View Scope='RecursiveAll'><Query></Query> <RowLimit>5000</RowLimit></View>";
        camlQuery.ListItemCollectionPosition = position;
        Microsoft.SharePoint.Client.ListItemCollection listItems = oList.GetItems(camlQuery);
        clientContextobj.Load(listItems);
        clientContextobj.ExecuteQuery();
        items.AddRange(listItems);
        position = listItems.ListItemCollectionPosition;

        page++;
    }
    while (position != null);

    //throw new Exception("My Exception!");
}
catch (Exception ex)
{
    //WSSLogger.Log("Loop Count:" + items.Count.ToString(), ex, RequestUrlAuthority);
}

try
{
    filteritems = items.Where(item => (item.FieldValues["Cust_Name"] == null ? string.Empty : item.FieldValues["Cust_Name"].ToString()) == strCustName
        && (item.FieldValues["Cust_Country"] == null ? string.Empty : item.FieldValues["Cust_Country"].ToString()) == strCountry &&
        (item.FieldValues["Status"] == null ? string.Empty : item.FieldValues["Status"].ToString()) == "Pending");

    //Pending,Active
}
catch (Exception ex)
{
    //WSSLogger.Log("-Custinfo-", ex, RequestUrlAuthority);
}    
  • Where do i use this code? at the moment i have only used CSR – Jonas Olesen Dec 14 '17 at 11:38
  • using (ClientContext ctx = new ClientContext("SiteUrl")) { SecureString pwd = new SecureString(); foreach (char c in "your password".ToCharArray()) pwd.AppendChar(c); ctx.Credentials = new SharePointOnlineCredentials("Username", pwd); Web web = ctx.Web; ctx.Load(web); ctx.ExecuteQuery(); SP.List oList = ctx.Web.Lists.GetByTitle("YourList"); ctx.Load(oList); ctx.ExecuteQuery(); After this you can add the above code – Indrani Armugam Dec 15 '17 at 12:39
  • you can change it as per CSR, first Load the list & then try to get the list items by overcoming threshold using the code above – Indrani Armugam Dec 15 '17 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.