Here is my code snippet. First Guid operation is being skipped. Need help
for (var i = 0; i < _dataparams.length; i++) {
var addressId = decodeURIComponent(_dataparams[i]).replace(/\+/g, " ").split("=");
var Guid = addressId.toString();
var checkBox = document.getElementById("chkBox");
var content = document.getElementById("content").value;
if (Guid != "" || Guid != undefined) {
var query = "?$select=homenet_addressstatus";
Xrm.WebApi.retrieveRecord("homenet_address", Guid, query).then(
function success(result) {
var addressStatus = result.homenet_addressstatus;
console.log("address status:" + addressStatus);
if (addressStatus != undefined) {//deactivate record
var entity = {};
entity.statecode = 1;
var entityName = "homenet_address";
console.log("address status and check box value:" + addressStatus, checkBox.checked);
if (addressStatus == 2 && checkBox.checked == true) {
entity.homenet_sendaddresscancelemail = true;
entity.homenet_canceladdressemailcontent = content;
}
Xrm.WebApi.updateRecord(entityName, Guid, entity,
function (output) {
if (output.success) {
console.log("Record updated successfully.");
} else {
console.log("Error in updating record:" + this.statusText);
}
});
console.log("retrieved address status value:" + addressStatus);
}
});
}
else {
console.log("Error in RetriveSingleRecord: " + output.data.message);
}
}
}
catch (e) {
console.log("Error in deactivating address record " + e.message);
}
}