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;
}