Using FetchXml Retrieve more than 5000 records with XrmSvcToolkit in MS CRM
var pagingNo;
var pageCookie = "";
var FetchXmlBuilder = function () {
return {
getPageCookie: function (a) {
return a;//.replace(/</gi, "<").replace(/>/gi, ">").replace(/\"/gi, """)
}
}
}();
var Bind_Results = new Array();
function xrmSvcTooltRequest() {
var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' page='" + pagingNo + "' count='5000' paging-cookie='" + pageCookie + "'>" +
"<entity name='apy_jobpackagetasks'>" +
"<attribute name='apy_jobpackagetasksid' />" +
"<attribute name='apy_name' />" +
"<attribute name='createdon' />" +
"<order attribute='apy_name' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<condition attribute='apy_escalationcontactid' operator='eq' uiname='purushotham' uitype='systemuser' value='{BE7A3ADF-0E14-DF11-BC3E-00505693620A}' />" +
"</filter>" +
"</entity>" +
"</fetch>";
XrmSvcToolkit.fetch({
fetchXml: fetch,
async: false,
successCallback: function (result) {
alert("success");
debugger;
if (result.moreRecords) {
pagingNo = pagingNo + 1;//this is for pagenumber
pageCookie = FetchXmlBuilder.getPageCookie(result.pageCookie);//this is used for to get cookie value
for (var rec = 0; rec < result.entities.length; rec++) {
if (result.entities[rec]["apy_jobpackagetaskid"] != null && result.entities[rec]["apy_jobpackagetaskid"].Id != null) {
for (var type = 0; type < resultcollection.length; type++) {
if (result.entities[rec]["apy_jobpackagetaskid"].Id == resultcollection[type]["apy_jobpackagetypeid"]) {
Bind_Results.push(result.entities[rec]);//result is pushing in an array
}
}
}
}
xrmSvcTooltRequest();//if we hav more record we will call again
//alert("S4");
return;
}
for (var rec = 0; rec < result.entities.length; rec++) {
if (result.entities[rec]["apy_jobpackagetaskid"] != null && result.entities[rec]["apy_jobpackagetaskid"].Id != null) {
for (var type = 0; type < resultcollection.length; type++) {
if (result.entities[rec]["apy_jobpackagetypeid"].Id == resultcollection[type]["apy_jobpackagetypeid"]) {
Bind_Results.push(result.entities[rec]);
}
}
}
}
buildData(Bind_Results);//this method is using to bind the data to table
},
errorCallback: function (error) {
alert(error);
}
});
}
var pageCookie = "";
var FetchXmlBuilder = function () {
return {
getPageCookie: function (a) {
return a;//.replace(/</gi, "<").replace(/>/gi, ">").replace(/\"/gi, """)
}
}
}();
var Bind_Results = new Array();
function xrmSvcTooltRequest() {
var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' page='" + pagingNo + "' count='5000' paging-cookie='" + pageCookie + "'>" +
"<entity name='apy_jobpackagetasks'>" +
"<attribute name='apy_jobpackagetasksid' />" +
"<attribute name='apy_name' />" +
"<attribute name='createdon' />" +
"<order attribute='apy_name' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<condition attribute='apy_escalationcontactid' operator='eq' uiname='purushotham' uitype='systemuser' value='{BE7A3ADF-0E14-DF11-BC3E-00505693620A}' />" +
"</filter>" +
"</entity>" +
"</fetch>";
XrmSvcToolkit.fetch({
fetchXml: fetch,
async: false,
successCallback: function (result) {
alert("success");
debugger;
if (result.moreRecords) {
pagingNo = pagingNo + 1;//this is for pagenumber
pageCookie = FetchXmlBuilder.getPageCookie(result.pageCookie);//this is used for to get cookie value
for (var rec = 0; rec < result.entities.length; rec++) {
if (result.entities[rec]["apy_jobpackagetaskid"] != null && result.entities[rec]["apy_jobpackagetaskid"].Id != null) {
for (var type = 0; type < resultcollection.length; type++) {
if (result.entities[rec]["apy_jobpackagetaskid"].Id == resultcollection[type]["apy_jobpackagetypeid"]) {
Bind_Results.push(result.entities[rec]);//result is pushing in an array
}
}
}
}
xrmSvcTooltRequest();//if we hav more record we will call again
//alert("S4");
return;
}
for (var rec = 0; rec < result.entities.length; rec++) {
if (result.entities[rec]["apy_jobpackagetaskid"] != null && result.entities[rec]["apy_jobpackagetaskid"].Id != null) {
for (var type = 0; type < resultcollection.length; type++) {
if (result.entities[rec]["apy_jobpackagetypeid"].Id == resultcollection[type]["apy_jobpackagetypeid"]) {
Bind_Results.push(result.entities[rec]);
}
}
}
}
buildData(Bind_Results);//this method is using to bind the data to table
},
errorCallback: function (error) {
alert(error);
}
});
}
Comments
Post a Comment