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();
Hey guys, I think I solved it.
I had to "turn the entities around" like this:
let deleteCommand = Xrm.Page.context.getClientUrl() _webApiUrl "new_umbrellaopportunities(" umbrellaId ")/new_umbrellaopportunity_opportunity_umbrellaopportunity(" opportunityId ")/$ref";
So, at first I had the "opportunity" before the relationship name and I sent the opportunityId as the relationship guid. (giving the error)
Now, I put my custom entity first, put the custom entity guid as the Id and for the relationship I pass the opportunityId.
So it was like backwards from what I sort of "feel" that it should be but apparently not..
Hello Wahaj,
Good idea, I tried it now, added this line of code after the declaration of "deleteCommand".
deleteCommand = deleteCommand.replace("{", "").replace("}", "");
I could see that the braces were removed but I got the exact same error unfortunately..
Hi,
Can you try removing curly braces ({})from the umbrellaId?
Best,
Wahaj
I'm not quite sure which true/false that could be? Could you give me a hint?
May be you are missing false/true parameter in your code. Can you please check once ?
That is one of the pages I have seen and tried.. In my eyes I'm doing it exactly like that.. :/
Still get the error.
Please refer below blog for details, its working fine for me:
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,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156