locked
Web API - Set regarding on appointment RRS feed

  • Question

  • I'm running into difficulties using the new Dynamics Web API rest endpoint when trying to set regarding on an appointment. Has anyone successfully done this? Firstly, I struggled to figure out how to set the regarding directly on the entity and post it as part of the create. If you know how to do it this way I'd love an example.

    The other way (updating a single-valued navigation property) from this page (https://msdn.microsoft.com/en-us/library/mt607875(v=crm.8).aspx#bkmk_Changethereferenceinasingle) you can see see that a PUT should be available, but the example is for an opportunity:

    PUT [organization URI]/api/data/v8.0/opportunities(00000000-0000-0000-0000-000000000001)/customerid_account/$ref HTTP/1.1
    

    Next, looking at this page (https://msdn.microsoft.com/en-us/library/mt593026.aspx#bkmk_SingleValuedNavigationProperties) I can see that the single-valued navigation properties on appointment include this "regardingobjectid_account". So I would expect to be able to do this:

    https://[organization URI]/api/data/v8.0/appointments(00000000-0000-0000-0000-000000000002)/regardingobjectid_account/$ref?

    with an odata.id set in the payload to something like:

    https://[organization URI]/api/data/v8.0/accounts(6DBE6556-CA99-E511-80D5-6C3BE5BECDB4)

    But it throws back a "400 bad request":

    Error: Status Code:400 The target Entity Set of Navigation Property 'regardingobjectid_account' could not be found. This is most likely an error in the IEdmModel.

    What am I doing wrong?



    Friday, December 4, 2015 12:15 PM

Answers

  • Ok, figured it out and thought I'd add the answer here. From looking through the page https://msdn.microsoft.com/en-us/dynamics/crm/mt149070.aspx I spotted a section on "Associate entities on create". This revealed the ability to bind to an existing entity which I tried on the navigation property and it worked. So you'd end up with something like this:

                var meeting = {
                    subject: title,
                    scheduledstart: start,
                    scheduledend: end,
                    "regardingobjectid_account@odata.bind": "/accounts(" + entityId + ")"
                };

    Then just send that through as a create and it will set the regarding all in one go.

    Friday, December 4, 2015 3:45 PM