locked
Invalid Party Object Type 4002 RRS feed

  • Question

  • I am trying to create a Service Appointment though code.  I am developing against Dynamics 365.

    I am using a resource (as apposed to a system user in the Resource Party List.

    For some reason I am getting the following error:

    "An exception of type 'System.ServiceModel.FaultException`1' occurred in Microsoft.Xrm.Sdk.dll but was not handled in user code

    Additional information: Invalid Party Object Type 4002"

    Yet the Service Activity should be able to accept the resource. 

    Here is my code.  Hopefully it provides enough information for someone to see what I have done wrong here:

    public Guid CreateAndReserveAppointment(AppointmentProposal proposal, Guid resourceId, Guid serviceId, Guid incidentId)
            {
                Guard.ArgumentIsNotNull(proposal, "proposal");
    
                ActivityParty resourceAP = new ActivityParty
                {
                    PartyId = new EntityReference(Resource.EntityLogicalName, resourceId)
                };
    
                ServiceAppointment appt = new ServiceAppointment()
                {
                    Subject = RESERVED_APPT_SUBJECT,
                    ScheduledStart = proposal.Start,
                    ScheduledEnd = proposal.End,
                    ServiceId = new EntityReference(xrmHelper.Service.EntityLogicalName, serviceId),
                    RegardingObjectId = new EntityReference(Incident.EntityLogicalName, incidentId),
                    Resources = new ActivityParty[] { resourceAP }
                };
    
                CreateRequest req = new CreateRequest
                {
                    Target = appt
                };
    
                CreateResponse resp = (CreateResponse)Service.Execute(req);
    
                if (resp.id.Equals(Guid.Empty))
                    throw new ApplicationException("The system was unable to reserve the Appointment.");
    
                ReserveAppointment(resp.id);
                return resp.id;
            }

    Friday, January 13, 2017 9:08 AM

Answers

  • Should have been using "Equipment.EntityLogicName" for the PartyId.

    Stupid, stupid. :)

    For those interested it shares the same ID as Resource (in the same way that Resource shares the same ID as System User).

    Friday, January 13, 2017 2:42 PM

All replies

  • I should say that there is a BookRequest as well which I have also tried with the same result.
    Friday, January 13, 2017 9:11 AM
  • Should have been using "Equipment.EntityLogicName" for the PartyId.

    Stupid, stupid. :)

    For those interested it shares the same ID as Resource (in the same way that Resource shares the same ID as System User).

    Friday, January 13, 2017 2:42 PM