1
votes

I'm trying to remove value of field regardingobjectid from a appointment entity using Microsoft Dynamics 365 Web API. Not able to but it shows the below error:

{
  "error": {
    "code": "",
    "message": "The property 'regardingobjectid' does not exist on type 'Microsoft.Dynamics.CRM.appointment'. Make sure to only use property names that are defined by the type."

Request

PATCH https://XXXXXXX.crm.dynamics.com/api/data/v8.2/appointments(9de8ba18-8303-e911-8147-3863bb2eb450)

Headers:

Content-Type: application/json
Authorization: Bearer *Token*

Body:

{
  "subject": "Check Updates",
  "[email protected]": "/systemusers(51d09106-22b6-e811-8143-3863bb2ec140)",
  "[email protected]": "/systemusers(51d09106-22b6-e811-8143-3863bb2ec140)",
  "location": "",
  "description": "nuldasddsadsal",
  "statecode": 3,
  "scheduledstart": "2018-12-19T06:45:00Z",
  "scheduledend": "2018-12-19T07:15:00Z",
  "isalldayevent": false,
  "regardingobjectid": null,
  "activitypointer_activity_parties": [
    {
      "[email protected]": "/accounts(4a2612e2-664b-e411-93ff-0050569469bd)",
      "participationtypemask": "6"
    }
  ]
}
1

1 Answers

2
votes

Couple of things:

1.To update/overwrite a lookup field value using web api, we have to use single-valued navigation property [email protected]

var entity = {};
entity["[email protected]"] = "/accounts(1F496057-8DE7-E811-A97A-000D3A1A9EFB)";

var req = new XMLHttpRequest();
req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/appointments(6D78AD2C-5A16-E811-A955-000D3A1A9407)", 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 {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send(JSON.stringify(entity));

2.As said above PATCH is for updating value of all field types, except for removing lookup value (updating null in lookup) - we have to use DELETE

My SO question and Community blog post