I was trying to create an entity record using Xrm.WebApi.CreateRecord but I'm getting the following error.
"cannot find record to be updated"
please note that the field 'edm_donorid' exists in the form and the ID that I'm using to fill the fill also exists in the contacts.
var entity = {};
var type = result["_edm_donorid_value@Microsoft.Dynamics.CRM.associatednavigationproperty"];
if (type == "edm_DonorID_contact") {
entity["edm_DonorID_contact@odata.bind"] = "/contacts(" + result["_edm_donorid_value"] + ")";
}
else if (type == "edm_DonorID_account") {
entity["edm_DonorID_account@odata.bind"] = "/accounts(" + result["_edm_donorid_value"] + ")";
}
opener.Xrm.WebApi.createRecord("edm_bookreceiptdetail", entity)
.then(function success(record) {
console.log("record created with ID: " + record.id);
// perform operations on record creation
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
I found the problem and I fixed it.
"cannot find record to be updated" error comes when I disregarded filling fields that have a relation with another entity.
so, make sure to fill every mandatory field or fields related to any other entities when you create an entity record using JS.
Amer Azzam, Microsoft Dynamics 365 Developer