For an account I m trying to populate primarycontactid (lookup field) using the following code but CRM returns error "400 Bad Request"
Can you please guide how is this code wrong ? Or please if can provide a working sample of similar snario ?
var entity = {};
entity.primarycontactid = {
Id: "ba121cbc-6a41-e611-80e0-c4346bc58294",
LogicalName: "contact"
};
var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts(bf121cbc-6a41-e611-80e0-c4346bc58294)", true);
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 {
alert(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
*This post is locked for comments
I have the same question (0)