So, I followed some posts suggesting how to delete a lookup from an entity via webapi. But I can't get it to work myself.
Scenario: On opportunity I have created a lookup to a custom entity. Now I want to delete/set to null the lookup to the custom entity.
As I have understood it by reading online it is not possible to set the lookup to null via an "webapi.update", instead a "webapi.delete" needs to be used.
The error I get is:
The URI segment '$ref' is invalid after the segment 'new_umbrellaopportunity_opportunity_umbrellaopportunity({83740A6A-8C43-EB11-A812-0022489A2750})
The command I send to the delete command:
https://mercuridev.crm4.dynamics.com/api/data/v9.1/opportunities(3242f616-1437-4545-afb0-e5a555240854)/new_umbrellaopportunity_opportunity_umbrellaopportunity({83740A6A-8C43-EB11-A812-0022489A2750})/$ref
The javascript code:
let deleteCommand = Xrm.Page.context.getClientUrl() _webApiUrl "opportunities" "(" recordId ")/new_umbrellaopportunity_opportunity_umbrellaopportunity(" umbrellaId ")/$ref";
req.open("DELETE", deleteCommand, false);
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) {
req.onreadystatechange = null;
if (this.status === 204 || this.status === 1223) {
}
}
};
req.send();