We are in the process of remediation, re-engineering old JS web resources for latest D365 v9 sdk changes w.r.t Client scripting API improvements & deprecation.
W
Great news! You can set lookup field to null in PATCH request by adding this header to your request.
autodisassociate: true
And then you can use something like this to alter your lookup field in any way:
SetLookupField(requestBody, "systemusers", "msdfm_MyUser", null)
// Or
SetLookupField(requestBody, "systemusers", "msdfm_MyUser", "f5b0b514-aea8-ea11-a812-000d3a569fe1")
// ...
private static void SetLookupField(JObject requestBody, string typePlural, string name, string value)
{
if (!string.IsNullOrEmpty(value))
{
requestBody.Add($"{name}@odata.bind", $"/{typePlural}({value})");
}
else
{
requestBody.Add($"_{name.ToLower()}_value", null);
}
}
OP uses XMLHttpRequest anyway, so I thought, a way to do this using PATCH will be relevant here.