Hi all,
I want to compare two dates one is coming from 'currentDateTime = new Date()' and the other is coming from retrieve through web api my whole code is given below:
function msdyn_customerasset_OnChange() {
Retrieve_msdyn_customerasset();
}
function Retrieve_msdyn_customerasset() {
var customerassetLookupId = Xrm.Page.getAttribute("msdyn_customerasset").getValue()[0].id,
fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='msdyn_customerasset'>" +
" <attribute name='msdyn_name' />" +
" <attribute name='msdyn_customerassetid' />" +
" <attribute name='aw_shutdownrequired' />" +
" <attribute name='aw_policyexpirationdate' />" +
" <order attribute='msdyn_name' descending='true' />" +
" <filter type='and'>" +
" <condition attribute='msdyn_customerassetid' operator='eq' value='" + customerassetLookupId + "' />" +
" </filter>" +
" </entity>" +
"</fetch>",
encodedFetchXml = encodeURI(fetchXml),
queryPath = "/api/data/v8.2/msdyn_customerassets?fetchXml=" + encodedFetchXml,//You must change the entity name including s and you must see the version of your web api as here v8.2
requestPath = Xrm.Page.context.getClientUrl() + queryPath,
req = new XMLHttpRequest();
req.open("GET", requestPath, false);//false for sychronous request
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var returned = JSON.parse(this.responseText),
results = returned.value;
if (results.length == 1) {
setValuesof_msdyn_workorder(results);
}
} else {
alert(this.statusText);
}
}
};
req.send();
}
function setValuesof_msdyn_workorder(results) {//setValuesof_Service Order
var ShutdownRequired = results[0]["aw_shutdownrequired"];
if (ShutdownRequired != null && ShutdownRequired == true) {
Xrm.Page.getAttribute("aw_shutdownrequired").setValue(ShutdownRequired);
Xrm.Page.getControl("aw_shutdownstartdate").setVisible(true);
Xrm.Page.getControl("aw_shutdownenddate").setVisible(true);
} else if (ShutdownRequired != null && ShutdownRequired == false) {
Xrm.Page.getAttribute("aw_shutdownrequired").setValue(ShutdownRequired);
Xrm.Page.getControl("aw_shutdownstartdate").setVisible(false);
Xrm.Page.getControl("aw_shutdownenddate").setVisible(false);
}
var policyexpirationdate = results[0]["aw_policyexpirationdate"],
currentDateTime = new Date();
if (currentdate <= policyexpirationdate) {
Xrm.Page.getControl("aw_sendemailtovendor").setVisible(true);
Xrm.Page.getAttribute("aw_sendemailtovendor").setRequiredLevel("required");
} else {
Xrm.Page.getControl("aw_sendemailtovendor").setVisible(false);
Xrm.Page.getAttribute("aw_sendemailtovendor").setRequiredLevel("none");
}
}
Please do let me know. How can I compare two on this scenario?
Thanks
Regards,
AW