Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
SharePoint REST API
Developer environment
No response
What browser(s) / client(s) have you tested
Additional environment details
No response
Describe the bug / error
We have a list with over 1M items. The end goal is to filter the column InvDate based on date range.
The InvDate is an indexed single line of text column , However it throws the List View Threshold error while getting the item using RestAPI.
Code
function FilterDate()
{
//var initialUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('ClaimListNew')/Items?$select=ID,*";
var sdate = $('#sdate').val();
var edate = $('#edate').val();
var myQuery= _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/getbytitle('MyList')/items?$select=ID*";
myQuery+="&$filter=InvDate ge '" +sdate+ "' and InvDate le '" +edate+ "'";
myQuery+="&$top=4999";
myQuery+="&$orderby=ID desc";
// start the process
var getAllItemsRequest = GetAllItems(myQuery);
// wait for it all to complete
getAllItemsRequest.done(function (allItems) {
console.log(allItems);
}).fail(function (error) {
console.warn("Error getting all items");
console.warn(JSON.stringify(error));
});
}
Function to get all the list items
function GetAllItems(requestUrl) {
var deferred = $.Deferred();
$.ajax({
url: requestUrl,
method: "GET",
headers: {
"accept": "application/json;odata=verbose",
}
}).done(function (thisResult) {
if (thisResult.d.__next) {
// if the __next property is present,
// that measn that there's more to get,
// so don't start resolving things yet,
// just make the next request
var nextRequest = GetAllItems(thisResult.d.__next);
// since GetAllItems returns a promise,
// we have to wait for that promise to resolve
// before resolving the promise we made
// at the beginning of this function
nextRequest.done(function(nextResult) {
// nextResult should be a plain array of items,
// so we need to combine that with the array
// of items we got in this call in thisResult.d.results
var combinedResults = thisResult.d.results.concat(nextResult);
// then resolve the combined results back up to the next level
deferred.resolve(combinedResults);
}).fail(function(error) {
deferred.reject(error);
});
} else {
// __next doesn't exist, so
// there's nothing more to get, so
// start resolving the nested promises
deferred.resolve(thisResult.d.results);
}
}).fail(function (result) {
deferred.reject(result);
});
return deferred.promise();
};
The above function has retrieved all 1 Million items without any filters as below
var myQuery= _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/getbytitle('ClaimlistNew')/items?$select=ID,*";

When we use query with the below filter , we get the threshold error
var myQuery= _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/getbytitle('MyList')/items?$select=ID*"; myQuery+="&$filter=InvDate ge '" +sdate+ "' and InvDate le '" +edate+ "'"; myQuery+="&$top=4999"; myQuery+="&$orderby=ID desc";
The end goal is to filter the InvDate column with the date range.
Would be grateful if anyone could let me know how this can be achieved.
Steps to reproduce
- In RestApi , use the filter and we get a threshold error
var myQuery= _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/getbytitle('MyList')/items?$select=ID*"; myQuery+="&$filter=InvDate ge '" +sdate+ "' and InvDate le '" +edate+ "'"; myQuery+="&$top=4999"; myQuery+="&$orderby=ID desc";
- When we use the queries without any filters , all the list Items are retrieved as below
var myQuery= _spPageContextInfo.webAbsoluteUrl +"/_api/web/lists/getbytitle('ClaimlistNew')/items?$select=ID,*";

Expected behavior
- The column on which the filter is being applied is an indexed column
- For the same reason , the filter applied based on range should fetch the desired result irrespective of the number of items returned , If not there should be a filter or a workaround to get the desired results
Target SharePoint environment
SharePoint Online
What SharePoint development model, framework, SDK or API is this about?
SharePoint REST API
Developer environment
No response
What browser(s) / client(s) have you tested
Additional environment details
No response
Describe the bug / error
We have a list with over 1M items. The end goal is to filter the column InvDate based on date range.
The InvDate is an indexed single line of text column , However it throws the List View Threshold error while getting the item using RestAPI.
Code
Function to get all the list items
The above function has retrieved all 1 Million items without any filters as below
When we use query with the below filter , we get the threshold error
The end goal is to filter the InvDate column with the date range.
Would be grateful if anyone could let me know how this can be achieved.
Steps to reproduce
Expected behavior