RE: Associate entities with web api using alternative keys
Okay, i figured it out by myself:
function createWithAKey() {
debugger;
try {
var clientUrl = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open("POST", encodeURI(clientUrl + "/api/data/v8.0/kc_legal_entities"), true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
debugger;
if (this.status == 204) {
}
}
};
var body = '{' +
'"kc_name":"Test 2",' +
'"kc_accountid@odata.bind":"/accounts(04F780FE-3265-E611-80CC-0025900A4E7D)",'+
'"kc_countryid@odata.bind":"/kc_countries(kc_country_code=\'40\')"' +
'}';
req.send(body);
} catch (e) {
}
}