When we fetch the data using Odata Query, we get only 10 records but if we need more than 10 records then how could we do this. Here i will show you two methods, with the help of these methods we can retrieve more than 10 records.
Method 1: Increase the page size.
Step 1: In this method, we don't need to change the code. Just go to Entity List from where you are retrieve the data. Open Entity List and increase the Page size number. Here i am changing it from 10 to 100. By default it;s size is 10.
Now check the data, you will get 100 records.
Method 2: Using Recursive.
Step 1: With the help of recursion, we can retrieve more than 10 records. Copy the below code and paste in your code editor.
Now check the result, you will get all the records.
Method 1: Increase the page size.
Step 1: In this method, we don't need to change the code. Just go to Entity List from where you are retrieve the data. Open Entity List and increase the Page size number. Here i am changing it from 10 to 100. By default it;s size is 10.
Now check the data, you will get 100 records.
Method 2: Using Recursive.
Step 1: With the help of recursion, we can retrieve more than 10 records. Copy the below code and paste in your code editor.
var result ;
function getData(){
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "~/_odata/Cases" ,
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {
result = data.value ;
url = data["odata.nextLink"];
if(url)
getMoreData(url);
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
}
function getMoreData(url){
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: url ,
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {
result = result.concat(data.value);
url = data["odata.nextLink"];
if(url)
getMoreData(url);
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
}
function getData(){
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "~/_odata/Cases" ,
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {
result = data.value ;
url = data["odata.nextLink"];
if(url)
getMoreData(url);
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
}
function getMoreData(url){
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: url ,
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
async: false,
success: function(data, textStatus, xhr) {
result = result.concat(data.value);
url = data["odata.nextLink"];
if(url)
getMoreData(url);
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
}
Now check the result, you will get all the records.
1 comment:
Its very useful blog post!!!!
Organized Retail in Mumbai
Unorganized Retail in Mumbai
Dealer Locations in Delhi
Geo-mapping in Gurugram
Post a Comment