web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to update the ActivityParty of an existing appointment using dynamics 365 webapi v9.0

(0) ShareShare
ReportReport
Posted on by

I would like to update the ActivityParty of an already existing appointment in dynamics 365 9.0 using the webapi v9.0. My goal is to update the required attendees and the optional attendees field.

I am trying to create a PUT request as described in the documentation of the webapi under Associate entities on update using collection-valued navigation property.

docs.microsoft.com/.../associate-disassociate-entities-using-web-api

Below you find the code i am using:

var activity = {};
var parties = [];

var requiredAttendee = {};
requiredAttendee["partyid_lead@odata.bind"] = "/leads(3fcc8c7b-e38d-e911-90f8-005056879361)";
requiredAttendee["participationtypemask"] = 5;

var optionalAttendee = {};
optionalAttendee["partyid_account@odata.bind"] = "/accounts(2e1261de-77cf-4f9b-a1bb-ff3a1f5a4add)";
optionalAttendee["participationtypemask"] = 6;

parties.push(requiredAttendee);
parties.push(optionalAttendee);

activity["value"] = parties;

var req = new XMLHttpRequest();
           req.open("PUT", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/appointments(20064d15-728e-e911-90f8-005056879361)/appointment_activity_parties", true);
           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) {
                   } else {
                       Xrm.Utility.alertDialog(this.statusText);
                   }
               }
           };
           req.send(JSON.stringify(activity));

I would expect that the request is successful. However i get a Bad Request with the following error message:

An error occurred while validating input parameters: System.InvalidCastException: Unable to cast object of type 'System.Web.OData.Formatter.Deserialization.ODataResourceWrapper' to type 'System.Web.OData.Formatter.Deserialization.ODataNestedResourceInfoWrapper'.

Does anyone have an idea what I am doing wrong?

*This post is locked for comments

I have the same question (0)
  • Macoy Profile Picture
    275 on at

    Hi Jonathan,

    Try this

    var requiredAttendee = {};

    requiredAttendee["partyid_lead@odata.bind"] = "/leads(3fcc8c7b-e38d-e911-90f8-005056879361)";

    requiredAttendee["participationtypemask"] = 5;

    var optionalAttendee = {};

    optionalAttendee["partyid_account@odata.bind"] = "/accounts(2e1261de-77cf-4f9b-a1bb-ff3a1f5a4add)";

    optionalAttendee["participationtypemask"] = 6;

    var data =

       {

           "requiredattendees": requiredAttendee,

           "optionalattendees": optionalAttendee        

       }

    // update the record

    Xrm.WebApi.updateRecord("appointment", "20064d15-728e-e911-90f8-005056879361", data).then(

       function success(result) {

           console.log("appointment updated");

           // perform operations on record update

       },

       function (error) {

           console.log(error.message);

           // handle error conditions

       }

    );

    Regards,

    Macoy

  • Jonathan Baettig Profile Picture
    on at

    Hi Macoy

    Thank you for your answer and sorry for my late response.

    Unfortunately, updating the fields "requiredattendees" and "optionalattendees" directly on the appointment does not work neither. I get the following error when executing your example:

    An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.

    I think updating the party fields directly on the appointment entity is generally not possible. There must be a way to associate the activity party to my appointment like described in the link i added to my post...

    Best regards,

    Jonathan

  • pawin Profile Picture
    249 on at

    Did you resolve this? I'm getting the same

  • Saad Kabarousse Profile Picture
    734 on at

    Hello,

    i would suggest to send two requests the first is (Retrieve ActivityParties associated to ur acitivity ) the second is an update request as shown below : 

    var entity = {};
    entity["partyid_account@odata.bind"] = "/accounts(66586A0-4222-EA11-B806-001DD8B71D5E)";
    entity["activityid@odata.bind"] = "/activitypointers(81DF86A0-4222-EA11-B806-001DD8B71D5E)";

    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/activityparties(81DF86A0-4222-EA11-B806-001DD8B71D5E)", 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));

  • pawin Profile Picture
    249 on at

    You can't retrieve activity parties:

    Invoke-RestMethod : {"error":{"code":"0x80040800","message":"The 'Retrieve' method does not support entities of type 'activityparty'

    And if I try to add activity parties to an activity with what you've got, I get:

    Invoke-RestMethod : {"error":{"code":"0x0","message":"An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type

    That was sending this as the body:

    $userActivityParty = @{
      "partyid_systemuser@odata.bind" = "/systemusers($userId)"
      "activityid@odata.bind" = "/activitypointers($appointmentId)"
      "participationtypemask" = 5
    }

  • pawin Profile Picture
    249 on at

    I've got it working by following http://himbap.com/blog/?p=2557

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans