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);
}
}
Hi,
Please try below code:
function ab() { var condition = ""; for (var i = 0; i < _dataparams.length; i ) { condition = "" _dataparams[i] "" } var fetchXML = "" "" "" "" "" "" condition "" "" "" ""; Xrm.WebApi.retrieveMultipleRecords("homenet_address", "?fetchXml=" fetchXML).then( function success(result) { for (var i = 0; i < result.entities.length; i ) { var currentEnt = result.entities[i]; if (currentEnt.homenet_addressstatus != undefined && currentEnt.homenet_addressstatus == 2 && checkBox.checked == true) { var entity = {}; entity.statecode = 1; entity.homenet_sendaddresscancelemail = true; entity.homenet_canceladdressemailcontent = content; // update the record Xrm.WebApi.updateRecord("homenet_address", currentEnt.homenet_addressid, entity).then( function success(result) { console.log("homenet_address updated"); }, function (error) { console.log(error.message); // handle error conditions } ); } } // perform additional operations on retrieved records }, function (error) { console.log(error.message); // handle error conditions } ); }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156