more than 5000 records retrieving using Web Api request in html page
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Pre cost Editor</title>
<script src="../../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="../../apyexp_scripts/jquery1.5.1.js" type="text/javascript"></script>
<script src="../../apyexp_scripts/jquery1.4.4.min.js" type="text/javascript"></script>
<script src="../../apyexp_scripts/json2.js" type="text/javascript"></script>
<script src="../../apyexp_/Script/XrmSvcToolkit.js" type="text/javascript"></script>
<script src="../../apyexp_scripts/SDK.MetaData.js" type="text/javascript"></script>
<script src="../../apyexp_/Script/Precosteditor.js" type="text/javascript"></script>
<!--<script src="../../apyexp_/Script/crmwebapi.js" type="text/javascript"></script>-->
<link rel="stylesheet" href="../../apyexp_/Styles/JqueryDatePickerTheams.css" />
<script src="../../apyexp_/Scripts/JqueryUiDatePicker.js"></script>
<link rel="stylesheet" href="../../apyexp_/Style/JqueryDatepickerResourse.css" />
<script>
$(function () {
$("#fromdate").datepicker({
numberOfMonths: 1,
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
$("#todate").datepicker("option", "minDate", dt);
}
});
$("#todate").datepicker({
numberOfMonths: 1,
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() - 1);
$("#fromdate").datepicker("option", "maxDate", dt);
}
});
});
</script>
<style type="text/css">
body {
font-family: Segoe UI, Tahoma, Arial;
font-size: 11px;
color: #000;
margin: 0px;
padding: 0px;
overflow: hidden;
}
.loadingpanel {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
z-index: 10000000;
background: rgba(255,255,255,0.7);
display: block;
}
.tbl_Grid {
table-layout: fixed;
width: 100%;
border-left: #b9b9b9 solid 1px;
border-top: #b9b9b9 solid 1px;
}
.tbl_Grid th {
background-color: #ffffff;
border-bottom: #b9b9b9 solid 1px;
border-right: #b9b9b9 solid 1px;
text-align: left;
padding: 0px;
font-weight: 500;
}
.tbl_Grid td {
border-bottom: #b9b9b9 solid 1px;
border-right: #b9b9b9 solid 1px;
padding: 5px 10px;
}
#mouseOverButtons input {
padding: 2px 7px;
margin-left: 5px;
min-width: 80px;
}
#editButtons input {
padding: 2px 7px;
margin-left: 5px;
min-width: 80px;
}
.search_div {
margin-right: 0px;
}
.search_div input[type="text"] {
width: 250px;
border: 1px solid #c6c6c6;
border-right: none;
outline: none;
text-indent: 5px;
position: relative;
top: -3px;
padding: 3px 0 2px 5px;
}
.search_div a img {
position: relative;
top: 3px;
right: 2px;
border: 1px solid #c6c6c6;
border-left: none;
padding: 1px 2px 1px 0;
height: 18px;
}
.search_div a {
padding: 0;
display: inline-block;
}
#serchimg {
border: 1px solid #a5acb5;
border-left: none;
position: relative;
padding: 2px 2px 2px 0;
top: 3px;
right: 5px;
}
#dateCalender {
/*border: 1px solid #a5acb5;*/
border-left: none;
position: relative;
padding: 2px 2px 2px 0;
top: 6px;
right: -2px;
}
#todatedateCalender {
/*border: 1px solid #a5acb5;*/
border-left: none;
position: relative;
padding: 2px 2px 2px 0;
top: 6px;
right: -2px;
}
.table_header {
/*width: auto;*/
padding: 0px;
margin: 5px 0 0 0;
border-top: 1px solid #dfdfdf;
padding-right: 0px;
border-bottom: 1px solid #dfdfdf;
overflow: hidden;
}
.table_header table {
width: 100%;
margin: 0px;
padding: 0px;
background-color: #fff;
}
.table_header table th {
font-size: 12px;
font-weight: 400;
border-right: 1px solid #dfdfdf;
padding: 0 10px;
text-align: left;
cursor: default;
}
.tbl_Grid table th:last-child {
border-right: 0px solid #dfdfdf;
}
.table_header tr:hover {
background-color: #D7EBF9;
}
.table_header table td {
font-size: 11px;
font-weight: normal;
padding: 5px 10px;
cursor: default;
}
.table_header table tr th:hover {
background-color: #D7EBF9;
cursor: pointer;
}
.table_header table td a {
color: #000;
}
table.header_tbl th {
border-right: solid 1px #d2d2d2;
text-align: left;
padding: 0px 4px;
font-weight: normal;
}
table.header_tbl th:last-child {
border-right: none;
}
.body_tbl tr:hover {
background-color: #d7ebf9;
}
table.header_tbl td {
text-align: left;
font-weight: normal;
padding: 3px 4px;
padding-right: 15px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
table.header_tbl th .right-border {
padding: 0 4px 0 3px;
border-right: none;
}
.refresh_img {
float: right;
}
</style>
</head>
<body>
<div>
<div id="heading">
<table class="tbl_Grid" style="font-size: 13px;">
<tbody>
<tr>
<th>Pre cost Editor
</th>
</tr>
</tbody>
</table>
</div>
<div class="loadingpanel" id="back_loading">
<img style="left: 45%; top: 50%; position: absolute; z-index: 1000;" alt="imageWhileLoading" src="/_imgs/advfind/progress.gif">
</div>
<div>
<table>
<td style="width: 240px;">
<div>
<table>
<td>
<span>amount is</span>
</td>
<td>
<select multiple="multiple" id="timepostingType" size="4" style="width: 110px;">
<option value="new" selected>New</option>
<option value="approved">Approved</option>
<option value="reject">Rejected</option>
</select>
</td>
</table>
</div>
</td>
<td>
<div style="padding: 0 5px;">
<table style="width: 100%; margin: 15px 0;" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<td style="width: 350px;">View amounts Between Dates:-<input type="text" name="fromdate" id="fromdate" /><img id="dateCalender" src="../../apyexp_/Image/CalenderDatePickerImage.png" onclick="$('#fromdate').datepicker('show')" />
</td>
<td style="width: 180px;">
<input type="text" name="toDate" id="todate" /><img id="todatedateCalender" src="../../apyexp_/Image/CalenderDatePickerImage.png" onclick="$('#todate').datepicker('show')" />
</td>
<td style="width: 30px;">OR</td>
<td style="width: 50px;">
<input type="checkbox" id="allCheckbox" name="allexp" />All</td>
</tr>
</tbody>
</table>
</div>
<div class="search_div" style="margin: 10px 0;">
<table style="width: 100%; padding: 0 5px;">
<tbody>
<tr>
<td style="width: 50px">FilterBy:</td>
<td style="width: 500px;">
<input type="text" id="txtSearch" name="searchtextbox" />
<img id="serchimg" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAATpJREFUeNpi/P//PwMlgAVEpKWlMTAyMjKADJs9ezZcMjU11R4oXgQUNwbxgeyzQHYfUM1BEB+kngmXyUBDK4AaDgCZfkBaGoSh7AMgOZg6rAYAbbYDUi1A/AuIi4GaZEAYaGMNVKwFaIgN3AtIAGTgPyBuBWJmIK6ZNWtWH5J8K1DjXyDdDrXAAWwAkr//Qf2qCzadhWUBuut+//49l5WVFWSAAU4vEAOA3mHGaQBQ8jKI/vPnTyy6HND2BFiMYAsDGOgGYlAgtQAD9BdQ00qogVFQv4PCoQZsECguQWkABpKTk4WYmZl3AZnGeHxQCQzcDox0gKwZKHkTaHAokL0JyH4BwlC2A0gzTA/cBeiagc52mDZt2gsCAQlxQWFhISepmlFSYn9//3cgtZVUzXAvUAKYGCgEAAEGAOfRkmo+O8IsAAAAAElFTkSuQmCC" />
</td>
<td>
<input id="btnApprove" style="margin-left: 3px; float: none;" type="button" value="Approve" />
</td>
<td>
<input class="coffee_btn" id="btnReject" style="margin-left: 3px; float: none;" type="button" value="Reject" /></td>
</tr>
</tbody>
</table>
</div>
</td>
</table>
</div>
<div style="background: rgb(255, 255, 255); *padding-right: 0px; font-family: Segoe UI, Arial, sans-serif; margin-top: 10px; padding: 0 5px;">
<div style="border-top: solid 1px #d6d6d6; border-bottom: solid 1px #d6d6d6; padding: 4px 0px; padding-right: 17px; background-color: rgb(241, 244, 247);">
<table class="header_tbl" style="table-layout: fixed; text-align: left; border-collapse: collapse; width: 100%; background-color: rgb(241, 244, 247);" cellpadding="0" cellspacing="0">
<colgroup>
<col style="width: 20px;" />
<col style="width: 20px; display:none;" />
<col style="width: 60px; display:none;" />
<col style="width: 60px; display:none;" />
<col style="width: 60px;" />
<col style="width: 50px; display:none;" />
<col style="width: 50px; display:none;" />
<col style="width: 50px; display:none;" />
<col style="width: 80px; display:none;" />
<col style="width: 50px; display:none;" />
<col style="width: 50px;" />
<col style="width: 50px;" />
<col style="width: 50px; display:none;" />
<col style="width: 150px; display:none;" />
<col style="width: 50px;" />
<col style="width: 100px; display:none;" />
</colgroup>
<tr>
<th>
<input id="expCheckboxAll" type="checkbox" /></th>
<th style="display:none;"></th>
<th style="display:none;">Activity</th>
<th style="display:none;">Project</th>
<th>Account</th>
<th style="display:none;">Non cost</th>
<th style="display:none;">Actul</th>
<th style="display:none;">costable</th>
<th style="display:none;">Resource</th>
<th style="display:none;">Rate</th>
<th >Revenue</th>
<th>Approved</th>
<th style="display:none;">costed</th>
<th style="display:none;">costing Notes</th>
<th>Start Date <img class="refresh" id="Img1" title="Refresh list" onclick="resetBuildTable()" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAARdJREFUeNqUUqGOhDAQnd6uQGNIMASFQ/MPBBR8A+v5AgSGEPgB+AJwawjB4HCQoJBrUAQ8JPS2kztu7zizTTrNzLz3ZqYtoZTCO+vKDCEEnW3baFEU0Pc97PsOqqqCrutwuVwQwMSv38x5nqnrujCO46HWdR1UVQXTNNHb7YbaByGOYwRrmgaGYWDsfr9D0zQQhuFPT6xM27bUsiwaBMFpoCiKMMc2wxI0XzP8XQz06mdZRpBg2/avRJ7n/yow7MdrwDTNEzhNU2xnGAYUPQiCIAC70ueQR7W6rmlZliBJEiiKgkJHS77vg+d5sK4r8DyP5ZdlAY7jgOWeJHIa+vF40CRJ2Im+LMvgOA6Iong8HHn3a3wKMADDQ5ZqVMDNaAAAAABJRU5ErkJggg==" style="float: right; cursor:pointer" /></th>
<th style="display:none;">End Date
</th>
</tr>
</table>
</div>
<div style="overflow-y: scroll; height: 640px; border-bottom:1px solid #ccc; left: 0px; right: 0px">
<table class="body_tbl" id="Expdata" style="table-layout: fixed; text-align: left; border-collapse: collapse; width: 100%;" cellpadding="2" cellspacing="0">
<colgroup>
<col style="width: 20px;" />
<col style="width: 20px; display:none;" />
<col style="width: 60px; display:none;" />
<col style="width: 60px; display:none;" />
<col style="width: 60px;" />
<col style="width: 50px; display:none;" />
<col style="width: 50px; display:none;" />
<col style="width: 50px; display:none;" />
<col style="width: 80px; display:none;" />
<col style="width: 50px; display:none;" />
<col style="width: 50px;" />
<col style="width: 50px;" />
<col style="width: 50px; display:none;" />
<col style="width: 150px; display:none;" />
<col style="width: 50px;" />
<col style="width: 100px; display:none;" />
</colgroup>
<tbody>
</tbody>
</table>
</div>
<div>
<table style="left: 0px; width: 100%; bottom: 0px; position: fixed; background-color: rgb(241, 244, 247);">
<tbody>
<tr>
<td>
<div id="SelectedCount" style="font-size: 13px;">0 - 0 of 0 (0 selected)</div>
</td>
<td>
<table style="float: right;">
<tbody>
<tr>
<td>
<a id="firstpage_a" style="cursor: pointer;" onclick="firstPage()">
<img id="start_page" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAJCAYAAADkZNYtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAEtJREFUeNpiyMvL+w/CQMCAjpHFQWwmBhwgPz///8SJExlhbBDNRKxCrIpxKcRQjE8hhmKQQpgimCaciglpwOpBXBpwBh02DQABBgDzaE4gX2BDQQAAAABJRU5ErkJggg==">
</a>
</td>
<td>
<a id="previous_a" style="cursor: pointer;" onclick="previousPage()">
<img id="previous_page" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAASklEQVR4XpWPUQoAIAhDswPrWTzxoo9BpWEJg6eMDQVAe5meHc0MgQFsUlWszL2fSe4u5K26MlFpHRWqZ9JMIV+/rsw/X9N4N5MHEbSNUZ01U9wAAAAASUVORK5CYII=">
</a>
</td>
<td id="PageCount" style="padding: 0px 5px; font-size: 13px;">Page 1
</td>
<td>
<a id="next_a" style="cursor: pointer;" onclick="nextPage()">
<img id="next_page" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAATElEQVR4XpWPCwoAIAhDswPrWTyxMcKEBn2EwYPG0yQi2st0gJllO5kHRlUNBIwsrkzjbnN3AdPqc5lXV/gMNqYt7cn9Vvr+NT0k7xkVBY1RndW3lwAAAABJRU5ErkJggg==">
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
////////script Precosted editor.js
var inBetweenDate = "";
var searchCondition = "";
var statusCondition = "";
var pageNo = 1;
var count = 0;
var recordCount = 0;
var totalRecordCount = 0;
var endOn = 0; // Maximum value of the page
var startFrom = 0; // Minimum value of the page
var pageObj; // startFrom and endOn values of the page
var pageNo = 1; // Current page number
var totalPages = 1; // Total number of Pages
var ButtonImages = {}; // This object is to store images in base64 format
var serverUrl;//crm server url
var morePages = true;
ButtonImages.Previous = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAASklEQVR4XpWPUQoAIAhDswPrWTzxoo9BpWEJg6eMDQVAe5meHc0MgQFsUlWszL2fSe4u5K26MlFpHRWqZ9JMIV+/rsw/X9N4N5MHEbSNUZ01U9wAAAAASUVORK5CYII=";
ButtonImages.PreviousHover = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAExJREFUeNpi/P//PwMIMDIyMqCAomNgif+9lmAJJgZsAKoIGTARowhTIQ5FqArxKEJV2GfFSJxCAooxPYNDMfbgwaKYERbghABAgAEA1XIWDbjhokcAAAAASUVORK5CYII=";
ButtonImages.Next = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAATElEQVR4XpWPCwoAIAhDswPrWTyxMcKEBn2EwYPG0yQi2st0gJllO5kHRlUNBIwsrkzjbnN3AdPqc5lXV/gMNqYt7cn9Vvr+NT0k7xkVBY1RndW3lwAAAABJRU5ErkJggg==";
ButtonImages.NextHover = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAE1JREFUeNpi/P//PwMIMBYfhzD6rBgZkABMnokBHRQd+8+ABTBhE8SmGLtCLIpxK0RTjF8hkseYiFGEWyGaIuwKsSgChzMsQAkBgAADAJSfGA22sRKMAAAAAElFTkSuQmCC";
ButtonImages.HomePage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAJCAYAAADkZNYtAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAEtJREFUeNpiyMvL+w/CQMCAjpHFQWwmBhwgPz///8SJExlhbBDNRKxCrIpxKcRQjE8hhmKQQpgimCaciglpwOpBXBpwBh02DQABBgDzaE4gX2BDQQAAAABJRU5ErkJggg==";
ButtonImages.HomePageHover = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAEZJREFUeNpi+P//PwND0bH/YIwOoOIgNUwMuACaRiZiFGFXiM0JGApxKMJU2GfFSJxCPIqxewaLYtzBg6aYERzgRACAAAMAgEgd5aYL61YAAAAASUVORK5CYII=";
var pageCookies = "";
var flag = true;
var resultVal = null;
var res = false;
function getamountsTotalCount() {
totalRecordCount = null;
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" >' +
'<entity name="apyexp_amount">' +
'<all-attributes />' +
'<order attribute="apyexp_name" descending="false" />' +
'<filter type="and">' +
statusCondition +
inBetweenDate +
searchCondition +
'</filter>' +
'<link-entity name="work" from="activityid" to="apyexp_workid" visible="false" link-type="outer" alias="ta">' +
'<attribute name="apyexp_noncostingduration" />' +
'<attribute name="apyexp_costingnote" />' +
'<attribute name="actualend" />' +
'</link-entity>' +
'</entity>' +
'</fetch>';
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/apyexp_amounts?fetchXml=" + encodeURIComponent(fetchXml), false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response).value;
totalRecordCount = results.length;
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
//Get amounts
function getamounts(pageNo) {
"use strict";
$('#back_loading').show();
if (flag) {
getamountsTotalCount();
flag = false;
}
var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="100" paging-cookie="' + pageCookies + '" page="' + pageNo + '" >' +
'<entity name="apyexp_amount">' +
'<all-attributes />' +
'<order attribute="apyexp_name" descending="false" />' +
'<filter type="and">' +
statusCondition +
inBetweenDate +
searchCondition +
'</filter>' +
'<link-entity name="work" from="activityid" to="apyexp_workid" visible="false" link-type="outer" alias="ta">' +
'<attribute name="apyexp_noncostingduration" />' +
'<attribute name="apyexp_costingnote" />' +
'<attribute name="actualend" />' +
'</link-entity>' +
'</entity>' +
'</fetch>';
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/apyexp_amounts?fetchXml=" + encodeURIComponent(fetchXml), false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(JSON.parse(this.response)["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"], "text/xml");
pageCookies = xmlDoc.children[0].getAttribute("pagingcookie");
pageCookies = ((pageCookies != null && pageCookies != undefined) || pageCookies == "") ? decodeURIComponent(decodeURIComponent(pageCookies)).replace(/[<]/gi, '<').replace(/[>]/gi, '>').replace(/[",']/gi, '"') : '';
var results = JSON.parse(this.response).value;
resultVal = results.length;
res = true;
recordCount = 100;
buildTable(results);
} else {
$('#back_loading').hide();
// Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
$('#back_loading').hide();
}
function errorCallback(error) {
"use strict";
Xrm.Utility.alertDialog(error.message);
//$('#back_loading').hide();
}
function postBuildTable() {
"use strict";
pageObj = getMinandMaxPageValues();
if (pageNo < totalPages) {
$("#next_page").attr("src", ButtonImages.NextHover);
$("#next_a").removeClass("not-active");
} else if (totalPages === pageNo && totalRecordCount != 5000) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
} else if (resultVal < recordCount) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
} else if (totalPages === pageNo && totalRecordCount == 5000) {
$("#next_page").attr("src", ButtonImages.NextHover);
$("#next_a").removeClass("not-active");
$("#firstpage_a").removeClass("not-active");
$("#previous_a").removeClass("not-active");
} else {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
}
if ($("#txtSearch").val() !== "") {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else {
if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (0 selected)");
} else if (totalRecordCount >= 5000) {
$("#SelectedCount").text(1 + " - " + recordCount + " of " + totalRecordCount + "+ (0 selected)");
} else {
$("#SelectedCount").text(1 + " - " + recordCount + " of " + totalRecordCount + " (0 selected)");
}
}
} else {
if (pageNo === parseInt(1)) {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (0 selected)");
} else if (totalRecordCount >= 5000) {
$("#SelectedCount").text(1 + " - " + recordCount + " of " + totalRecordCount + "+ (0 selected)");
} else {
$("#SelectedCount").text(1 + " - " + recordCount + " of " + totalRecordCount + " (0 selected)");
}
} else {
if (totalRecordCount >= 5000) {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + "+ (0 selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (0 selected)");
}
}
}
}
function buildTable(result) {
"use strict";
//preBuildTable();
$("#Expdata > tbody").html("");
if (result !== null && typeof result !== "undefined") {
if (result.length > 0) {
recordCount = 100;
//totalRecordCount = result.totalRecordCount;
totalPages = Math.ceil(totalRecordCount / recordCount);
var tr;
var td;
var temp;
for (var i = 0; i < result.length; i++) {
//retrieveCurrency(result.entities[i].transactioncurrencyid.Name);
tr = $("<tr>").attr("id", result[i].apyexp_amountid).bind("dblclick", openCurrentRecord);
// CheckBox
td = $("<td>");
if (typeof (result[i].apyexp_amountid) !== "undefined" && result[i].apyexp_amountid !== null) {
temp = $("<input type =\"checkbox\" id=\"" + result[i].apyexp_amountid + "\">").bind("click", selectedCheckBoxCount);
} else {
continue;
}
temp.appendTo(td);
td.appendTo(tr);
temp = null;
//image
td = $("<td>").css("display", "none");
td.appendTo(tr);
temp = null;
//Activity
td = $("<td>").css("display", "none");
if (typeof (result[i].apyexp_workid) !== "undefined" && result[i].apyexp_workid !== null && typeof (result[i].apyexp_workid.Id) !== "undefined" && result[i].apyexp_workid.Id !== null) {
temp = $("<strong>");
$("<a id='\"'" + result[i].apyexp_workid.Id + "\" name=\"" + result[i].apyexp_workid.LogicalName + "\" href=\"#\">" + result[i].apyexp_workid.Name + "\</a>").bind("click", preOpenRecord).appendTo(temp);
} else {
temp = null;
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
//project
td = $("<td>").css("display", "none");
td.appendTo(tr);
temp = null;
//Account
td = $("<td>");
if (typeof (result[i].apyexp_accountid) !== "undefined" && result[i].apyexp_accountid !== null && typeof (result[i].apyexp_accountid.Id) !== "undefined" && result[i].apyexp_accountid.Id !== null) {
td.attr("label", result[i].apyexp_accountid.Name);
temp = $("<strong>");
$("<a id="A1"" + result[i].apyexp_accountid.Id + "\" name=\"" + result[i].apyexp_accountid.LogicalName + "\" href=\"#\">" + result[i].apyexp_accountid.Name + "\</a>").bind("click", preOpenRecord).appendTo(temp);
} else {
td.attr("label", "");
temp = null;
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
//Non cost
td = $("<td>").css("display", "none");
if (result[i].hasOwnProperty("ta.apyexp_noncostingduration") && typeof (result[i]["ta.apyexp_noncostingduration"]) !== "undefined" && result[i]["ta.apyexp_noncostingduration"] !== null) {
temp = $("<label>").text(result[i]["ta.apyexp_noncostingduration"]);
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
//Actual
td = $("<td>").css("display", "none");
td.appendTo(tr);
temp = null;
//costable
td = $("<td>").css("display", "none");
td.appendTo(tr);
temp = null;
//Resource
td = $("<td>").css("display", "none");
td.appendTo(tr);
temp = null;
//Rate
td = $("<td>").css("display", "none");
td.appendTo(tr);
temp = null;
//Revenue
td = $("<td>");
if (typeof (result[i].apyexp_totalamount) !== "undefined" && result[i].apyexp_totalamount !== null) {
temp = $("<label>").text(result[i].apyexp_totalamount);
//temp = $("<label>").text(currencySymbol + result.entities[i].apyexp_totalamount.Value);
} else {
td.attr("title", "");
temp = null;
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
//Approve
td = $("<td>");
temp = $("<input type =\"checkbox\" id=\"" + i + "\">").attr("disabled", true);
if (typeof (result[i].statuscode) !== "undefined" && result[i].statuscode !== null && result[i].statuscode !== "") {
if (result[i].statuscode === 810650003) {
temp.attr("checked", true).attr("statusValue", "approve");
} else if (result[i].statuscode === 810650005) {
temp.attr("statusValue", "reject");
} else if (result[i].statuscode === 810650000) {
temp.attr("statusValue", "new");
}
}
temp.appendTo(td);
td.appendTo(tr);
temp = null;
//costed
td = $("<td>").css("display", "none");
temp = $("<input type =\"checkbox\" id=\"cost" + i + "\">").attr("disabled", true);
temp.appendTo(td);
td.appendTo(tr);
temp = null;
//costing Notes
td = $("<td>").css("display", "none");
if (result[i].hasOwnProperty("ta.apyexp_costingnote") && result[i]["ta.apyexp_costingnote"] !== null && typeof (result[i]["ta.apyexp_costingnote"]) !== "undefined") {
temp = $("<label>").text(result[i]["ta.apyexp_costingnote"]);
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
//Start Date
td = $("<td>");
if (typeof (result[i].apyexp_amountdate) !== "undefined" && result[i].apyexp_amountdate !== null) {
temp = $("<label>").text(result[i].apyexp_amountdate);
} else {
td.attr("title", "");
temp = null;
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
//End Date
td = $("<td>").css("display", "none");
if (result[i].hasOwnProperty("ta.actualend") && result[i]["ta.actualend"] !== null && typeof result[i].hasOwnProperty("ta.actualend") && result[i]["ta.actualend"] !== "undefined") {
temp = $("<label>").text(result[i]["ta.actualend"]);
}
if (temp !== null && typeof (temp) !== "undefined") {
temp.appendTo(td);
}
td.appendTo(tr);
temp = null;
$("#Expdata").append(tr);
}
} else {
totalRecordCount = 0;
$("#LoadingPanel").hide();
$("#empty_records").show();
}
}
postBuildTable();
$('#back_loading').hide();
}
var currencySymbol;
function retrieveCurrency(name) {
"use strict";
if (name !== null && typeof (name) !== "undefined" && name !== "") {
currencySymbol = "";
if (name === "रुपया") {
currencySymbol = "₹";
} else if (name === "Australian Dollar") {
currencySymbol = "$";
} else if (name === "Canadian Dollar") {
currencySymbol = "$";
} else if (name === "Dansk krone") {
currencySymbol = "kr.";
} else if (name === "Euro") {
currencySymbol = "€";
} else if (name === "Norsk krone") {
currencySymbol = "kr";
} else if (name === "Peso") {
currencySymbol = "$";
} else if (name === "Pound Sterling") {
currencySymbol = "£";
} else if (name === "Real") {
currencySymbol = "R$";
} else if (name === "Schweizer Franken") {
currencySymbol = "Fr.";
} else if (name === "Singapore Dollar") {
currencySymbol = "$";
} else if (name === "Svensk krona") {
currencySymbol = "kr";
} else if (name === "US Dollar") {
currencySymbol = "$";
} else if (name === "солкуобай") {
currencySymbol = "с.";
} else if (name === "درهم اماراتي") {
currencySymbol = "د.إ.";
} else if (name === "원") {
currencySymbol = "₩";
} else if (name === "人民币") {
currencySymbol = "¥";
} else if (name === "円") {
currencySymbol = "¥";
}
}
}
function openCurrentRecord(e) {
"use strict";
if (typeof e === "undefined" || e === null) {
e = event;
}
var entityName = "apyexp_amount";
var recordId = e.currentTarget.firstChild.firstChild.id;
Xrm.Utility.openEntityForm(entityName, recordId)
}
function buttonsVisibility() {
"use strict";
var selectedRecords;
var approveCount = 0;
var rejectCount = 0;
var newCount = 0;
selectedRecords = $("#Expdata").find("td:first-child input:checkbox:checked");
var i = 0;
while (i < selectedRecords.length) {
if ($(selectedRecords[i]).closest("tr").find("td:eq(11) input:checkbox").attr("statusValue") === "approve") {
approveCount = approveCount + 1;
} else if ($(selectedRecords[i]).closest("tr").find("td:eq(11) input:checkbox").attr("statusValue") === "reject") {
rejectCount = rejectCount + 1;
} else {
newCount = newCount + 1;
}
i = i + 1;
}
if (approveCount + newCount === selectedRecords.length && selectedRecords.length > 0) {
$("#btnApprove").attr("disabled", true);
$("#btnReject").attr("disabled", false);
} else if (rejectCount + newCount === selectedRecords.length && selectedRecords.length > 0) {
$("#btnApprove").attr("disabled", false);
$("#btnReject").attr("disabled", true);
} else {
$("#btnApprove").attr("disabled", true);
$("#btnReject").attr("disabled", true);
}
if (approveCount === parseInt(0) && rejectCount === parseInt(0)) {
$("#btnApprove").attr("disabled", false);
$("#btnReject").attr("disabled", false);
}
if (selectedRecords.length === parseInt(0)) {
$("#btnApprove").attr("disabled", true);
$("#btnReject").attr("disabled", true);
}
}
function selectedCheckBoxCount() {
"use strict";
$('#back_loading').show();
buttonsVisibility();
count = 0;
pageObj = getMinandMaxPageValues();
if ($("#Expdata").find("td:first-child input:checkbox:checked").length > 0) {
for (var i = 0; i < $("#Expdata").find("td:first-child input:checkbox:checked").length; i++) {
if ($($("#Expdata").find("td:first-child input:checkbox:checked")[i]) !== null && typeof ($($("#Expdata").find("td:first-child input:checkbox:checked")[i])) !== "undefined" && $($("#Expdata").find("td:first-child input:checkbox:checked")[i]) !== "") {
count++;
}
}
if ($("#txtSearch").val() !== "") {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
} else {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
}
} else {
count--;
if (count === -1) {
count = 0;
}
if ($("#txtSearch").val() !== "") {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
//$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
//$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
}
if ($("#Expdata").find("td:first-child input:checkbox").length !== $("#Expdata").find("td:first-child input:checkbox:checked").length) {
$("#expCheckboxAll").attr("checked", false);
} else {
$("#expCheckboxAll").attr("checked", true);
}
$('#back_loading').hide();
}
function openRecord(entity, recordId) {
"use strict";
var windowOptions = {
openInNewWindow: true
};
Xrm.Utility.openEntityForm(entity, recordId, null, windowOptions);
}
function preOpenRecord(e) {
"use strict";
if (typeof e === "undefined" || e === null) {
e = event;
}
if (typeof e.currentTarget !== "undefined" && e.currentTarget !== null) {
openRecord(e.currentTarget.name, e.currentTarget.id);
}
}
function checkUncheckAllRows() {
"use strict";
$('#back_loading').show();
count = 0;
pageObj = getMinandMaxPageValues();
if ($("#expCheckboxAll").attr("checked")) {
$("#Expdata").find("td:first-child input:checkbox:enabled").attr("checked", true);
count = $("#Expdata").find("td:first-child input:checkbox:checked").length;//recordCount;
} else {
$("#Expdata").find("td:first-child input:checkbox:enabled").attr("checked", false);
count = 0;
}
if ($("#txtSearch").val() !== "") {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
} else {
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
} else if (totalRecordCount <= 100) {
$("#SelectedCount").text(1 + " - " + totalRecordCount + " of " + totalRecordCount + " (" + count + " selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
//$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (" + count + " selected)");
}
buttonsVisibility();
$('#back_loading').hide();
}
function setDateFilters() {
"use strict";
var startDate = $("#fromdate").val();
var endDate = $("#todate").val();
if (startDate <= endDate) {
if ($("#allCheckbox").attr("checked")) {
inBetweenDate = "";
} else if (startDate !== null && typeof (startDate) !== "undefined" && startDate !== "" && endDate !== null && typeof (endDate) !== "undefined" && endDate !== "") {
inBetweenDate = "<filter type=\"and\">" +
"<condition attribute=\"apyexp_amountdate\" operator=\"on-or-after\" value=\"" + startDate + "\" />" +
"<condition attribute=\"apyexp_amountdate\" operator=\"on-or-before\" value=\"" + endDate + "\" />" +
"</filter>";
}
}
}
function setStatusFilters() {
"use strict";
statusCondition = "<filter type=\"and\">" +
"<condition attribute=\"statuscode\" operator=\"in\">";
var temp = $("#timepostingType").val();
var i = 0;
while (i < temp.length) {
if (temp[i] === "new") {
statusCondition = statusCondition + "<value>810650000</value>";
} else if (temp[i] === "approved") {
statusCondition = statusCondition + "<value>810650003</value>";
} else if (temp[i] === "reject") {
statusCondition = statusCondition + "<value>810650005</value>";
}
i = i + 1;
}
statusCondition += "</condition></filter>";
}
function cancel() {
"use strict";
$("#back_loading").show();
$("#Cancel").css("display", "none");
$("#searchImg1").css("display", "block");
$("#txtSearch").val("");
flag = true;
searchCondition = "";
getamounts(1);
$("#back_loading").hide();
}
function setSearchFilter() {
"use strict";
var val = $("#txtSearch").val().toLowerCase().trim();
if (val !== "") {
searchCondition = "<filter type=\"or\">" +
"<condition attribute=\"apyexp_accountidname\" operator=\"like\" value=\"" + val + "%\" />" +
"<condition attribute=\"apyexp_workidname\" operator=\"like\" value=\"" + val + "%\" />" +
"</filter>";
} else {
searchCondition = "";
}
}
function searchRecords() {
"use strict";
$('#back_loading').show();
$("#expCheckboxAll").attr("checked", false);
$("#searchImg1").css("display", "none");
$("#Cancel").css("display", "block");
flag = true;
setSearchFilter();
setDateFilters();
setStatusFilters();
getamounts(1);
$('#back_loading').hide();
}
function resetBuildTable() {
"use strict";
"use strict";
$("#back_loading").show();
flag = true;
setStatusFilters();
setDateFilters();
setSearchFilter();
getamounts(1);
selectedCheckBoxCount();
$("#expCheckboxAll").attr("checked", false);
$("#back_loading").hide();
}
function firstPage() {
"use strict";
$("#back_loading").show();
$("#expCheckboxAll").attr("checked", false);
if (parseInt($("#PageCount").text().trim()[5]) == 1 && pageNo == 1) {
$("#back_loading").hide();
return;
}
pageNo = 1;
if (pageNo === parseInt(1)) {
getamounts(1);
}
$("#previous_page").attr("src", ButtonImages.Previous);
$("#start_page").attr("src", ButtonImages.HomePage);
$("#firstpage_a").addClass("not-active");
$("#previous_a").addClass("not-active");
if (totalPages <= 1) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
} else {
$("#next_page").attr("src", ButtonImages.NextHover);
$("#next_a").removeClass("not-active");
}
$("#PageCount").text("Page 1");
goToPage(pageNo);
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
}
$("#back_loading").hide();
}
function previousPage() {
"use strict";
$('#back_loading').show();
// pageNo = parseInt($("#PageCount").text().trim()[5]) - 1;
pageNo = pageNo - 1;
if (pageNo === parseInt(0) || pageNo == 1) {
$("#previous_page").attr("src", ButtonImages.Previous);
$("#start_page").attr("src", ButtonImages.HomePage);
$("#firstpage_a").addClass("not-active");
$("#previous_a").addClass("not-active");
}
if (pageNo < 1) {
pageNo = pageNo + 1;
$("#back_loading").hide();
return;
}
$("#expCheckboxAll").attr("checked", false);
if (pageNo !== parseInt(0)) {
getamounts(pageNo);
}
//pageNo = parseInt($("#PageCount").text().trim()[5]) - 1;
if (pageNo < totalPages) {
$("#next_page").attr("src", ButtonImages.NextHover);
$("#next_a").removeClass("not-active");
$("#firstpage_a").removeClass("not-active");
$("#previous_a").removeClass("not-active");
}
goToPage(pageNo);
$("#PageCount").text("Page " + pageNo);
$('#back_loading').hide();
}
function getPageCookie(a) {
return a.replace(/</gi, "<").replace(/>/gi, ">").replace(/\"/gi, """)
}
function nextPage() {
"use strict";
$('#back_loading').show();
if (resultVal < 0) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
return;
}
pageNo = pageNo + 1;
var nextData = true;
//pageNo = parseInt($("#PageCount").text().trim()[5]) + 1;
$("#expCheckboxAll").attr("checked", false);
if (pageNo !== parseInt(0)) {//&& totalPages < pageNo
$("#previous_page").attr("src", ButtonImages.PreviousHover);
$("#start_page").attr("src", ButtonImages.HomePageHover);
$("#firstpage_a").removeClass("not-active");
$("#previous_a").removeClass("not-active");
getamounts(pageNo);
nextData = false;
if (totalPages === pageNo && totalRecordCount != 5000) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
} else if (totalPages === pageNo && totalRecordCount != 5000) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
} else if (resultVal < recordCount) {
$("#next_page").attr("src", ButtonImages.Next);
$("#next_a").addClass("not-active");
} else {
$("#next_page").attr("src", ButtonImages.NextHover);
$("#next_a").removeClass("not-active");
$("#firstpage_a").removeClass("not-active");
$("#previous_a").removeClass("not-active");
}
}
if (totalPages == pageNo && nextData == true) {
getamounts(pageNo);
nextData = false;
$("#next_page").attr("src", ButtonImages.NextHover);
$("#next_a").removeClass("not-active");
$("#firstpage_a").removeClass("not-active");
$("#previous_a").removeClass("not-active");
} else if (totalPages < pageNo && nextData == true) {
getamounts(pageNo);
nextData = false;
if (res) {
pageNo = pageNo + 1;
$("#PageCount").text("Page " + pageNo);
$("#back_loading").hide();
} else {
pageNo = pageNo;//- 1;
$("#PageCount").text("Page " + pageNo);
$("#back_loading").hide();
return;
}
}
if (recordCount > 0) {
goToPage(pageNo);
}
//if (totalPages < pageNo) {
//if (res.entities.length == recordCount) {
// $("#previous_page").attr("src", ButtonImages.PreviousHover);
// $("#firstpage_a").removeClass("not-active");
// $("#previous_a").removeClass("not-active");
//}
////if (totalPages === pageNo && totalRecordCount != 5000) {
//// $("#next_page").attr("src", ButtonImages.Next);
//// $("#next_a").addClass("not-active");
////} else {
//// $("#next_page").attr("src", ButtonImages.NextHover);
//// $("#next_a").removeClass("not-active");
//// $("#firstpage_a").removeClass("not-active");
//// $("#previous_a").removeClass("not-active");
////}
$("#PageCount").text("Page " + pageNo);
$('#back_loading').hide();
}
function goToPage(pageNo) {
"use strict";
$("#expCheckboxAll").attr("checked", false);
pageObj = getMinandMaxPageValues();
var i = 0;
if ($("#txtSearch").val() !== "") {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + count + " (0 selected)");
} else if (totalRecordCount >= 5000 && pageObj.maxValue >= 5000) {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + pageObj.maxValue + "+ (0 selected)");
} else if (totalRecordCount >= 5000) {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + "+ (0 selected)");
} else {
$("#SelectedCount").text(parseInt(pageObj.minValue) + 1 + " - " + pageObj.maxValue + " of " + totalRecordCount + " (0 selected)");
}
var val = $("#txtSearch").val().toLowerCase().trim();
if ($("#txtSearch").val() !== "") {
if (val !== "") {
searchCondition = "<filter type=\"or\">" +
"<condition attribute=\"apyexp_accountidname\" operator=\"like\" value=\"" + val + "%\" />" +
"<condition attribute=\"apyexp_workidname\" operator=\"like\" value=\"" + val + "%\" />" +
"</filter>";
getamounts(1);
} else {
cancel();
}
}
}
function getMinandMaxPageValues() {
"use strict";
pageObj = new Object();
endOn = pageNo * recordCount;
startFrom = endOn - recordCount;
if (recordCount == resultVal) {
if ($("#txtSearch").val() !== "") {
if (endOn > count) {
endOn = count;
}
} else {
if (endOn > totalRecordCount)
endOn = totalRecordCount;
}
} else {
endOn = startFrom + resultVal;
}
pageObj.minValue = startFrom;
pageObj.maxValue = endOn;
return pageObj;
}
//Pre Approve validation
function preApproveAction(index, item) {
// "use strict";
var approvechkbox = $(item).closest("tr").find("td:eq(11) input:checkbox");
//if ($(approvechkbox).attr("checked") !== true) {
if (item.id !== null && typeof (item.id) !== "undefined" && item.id.length === parseInt(36)) {
changeRecordStatus("apyexp_amount", item.id, 1, 810650003, serverUrl);
}
//}
}
//Pre Reject validation
function preRejectAction(index, item) {
//"use strict";
var rejectchkbox = $(item).closest("tr").find("td:eq(11) input:checkbox");
//if ($(rejectchkbox).attr("checked") !== true) {
if (item.id !== null && typeof (item.id) !== "undefined" && item.id.length === parseInt(36)) {
changeRecordStatus("apyexp_amount", item.id, 1, 810650005, serverUrl);
}
//}
}
//Button Action for Approve or reject
function setApproveOrRejectActions(e) {
// "use strict";
flag = true;
$("#back_loading").show();
var selectedRecords;
if (typeof e === "undefined" || e === null) {
e = event;
}
if (typeof (e.currentTarget) !== "undefined" && e.currentTarget !== null) {
selectedRecords = $("#Expdata").find("td:first-child input:checkbox:checked");
if (e.currentTarget.value === "Approve") {
$(selectedRecords).each(preApproveAction);
} else if (e.currentTarget.value === "Reject") {
$(selectedRecords).each(preRejectAction);
}
}
$("#btnApprove").attr("disabled", true);
$("#btnReject").attr("disabled", true);
getamounts(1);
$("#back_loading").hide();
}
//change Record Status generic function
function changeRecordStatus(EntityLogicalName, RECORD_ID, stateCode, statusCode, serverUrl) {
var entity = {};
entity.statecode = stateCode;
entity.statuscode = statusCode;
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + EntityLogicalName + "s(" + RECORD_ID + ")", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
//Success - No Return Data - Do Something
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
//"use strict";
//XrmSvcToolkit.setState({
// entityName: EntityLogicalName,
// id: RECORD_ID,
// stateCode: stateCode,
// statusCode: statusCode,
// successCallback: function (result) {
// //Xrm.Utility.openEntityForm(entityname, RECORD_ID);
// },
// errorCallback: function (error) {
// Xrm.Utility.alertDialog(error.message);
// }
//});
}
//Get ServerUrl of Crm
function getServerMainUrl() {
"use strict";
var url = "";
url = Xrm.Page.context.getClientUrl();
return url;
}
function statusRelatedRecords() {
"use strict";
$("#fromdate").val("");
$("#todate").val("");
$("#txtSearch").val("");
flag = true;
setStatusFilters();
getamounts(1);
}
$(document).ready(function () {
"use strict";
$('#back_loading').show();
$("#btnApprove").attr("disabled", true);
$("#btnReject").attr("disabled", true);
$("#Expdata").click(function (e) {
if (e === null || typeof e === "undefined") {
e = event;
}
if ($("#" + e.target.parentElement.id).find("td input[type='checkbox']:first")[0].checked) {
$("#" + e.target.parentElement.id).find("td input[type='checkbox']:first")[0].checked = false;
} else {
$("#" + e.target.parentElement.id).find("td input[type='checkbox']:first")[0].checked = true;
}
var selectedRecords = $("#Expdata").find("td:first-child input:checkbox:checked");
if (selectedRecords.length === totalRecordCount) {
$("#expCheckboxAll").attr("checked", true);
} else {
$("#expCheckboxAll").attr("checked", false);
}
});
serverUrl = getServerMainUrl();
flag = true;
setStatusFilters();
getamounts(pageNo);
$("#expCheckboxAll").bind("click", checkUncheckAllRows);
$("#serchimg").bind("click", searchRecords);
$("#btnApprove").bind("click", setApproveOrRejectActions);
$("#btnReject").bind("click", setApproveOrRejectActions);
$("#timepostingType").bind("click", statusRelatedRecords);
$("#allCheckbox").attr("checked", true);
$("#txtSearch").keyup(function (e) {
count = 0;
if (e.keyCode === parseInt(13) || e.keyCode === parseInt(8)) {
if ($("#txtSearch").val() !== "") {
$("#searchImg1").css("display", "none");
$("#Cancel").css("display", "block");
var val = $("#txtSearch").val().toLowerCase().trim();
if (val !== "") {
flag = true;
searchCondition = "<filter type=\"or\">" +
"<condition attribute=\"apyexp_accountidname\" operator=\"like\" value=\"" + val + "%\" />" +
"<condition attribute=\"apyexp_workidname\" operator=\"like\" value=\"" + val + "%\" />" +
"</filter>";
getamounts(1);
} else {
cancel();
}
} else {
cancel();
}
}
firstPage();
if (totalRecordCount === parseInt(0)) {
$("#SelectedCount").text(0 + " - " + 0 + " of " + 0 + " (0 selected)");
}
});
$('#back_loading').hide();
});
Comments
Post a Comment