Hi All,
Hoping you can support on the best c# method for this using the organisation service proxy.
I am in the process of creating a contact, creating an account, linking them together and then creating the service activity appointment. I have successfully created the contact, account and the relationships between them, however I have stumbled on creating the service activity appointment.
I am having problems saving the related party lists such as adding 2 resources at once; a training room and a teacher. I would also like confirmation on whether I can use only the contact and service ID when linking them to the service activity appointment.
To start testing, I have hard coded the service activity name I would like to use when querying it to receive the ID but this isn't the issue. Please see what I have so far:
[code]
//Create the service appointment
//Does Service already exist?
QueryExpression serviceQuery = new QueryExpression
{
EntityName = "service",
ColumnSet = new ColumnSet("serviceid"),
Criteria = new FilterExpression()
};
serviceQuery.Criteria.AddCondition("name", ConditionOperator.Equal, "A Course");
EntityCollection resultService = _service.RetrieveMultiple(serviceQuery);
Entity resultServiceID;
//If it already exists, use it
if (resultService.Entities.Count > 0)
{
//result is the account ID
resultServiceID = _service.RetrieveMultiple(serviceQuery).Entities.FirstOrDefault();
sID = resultServiceID.Id;
Entity serviceActivity = new Entity("serviceappointment");
serviceActivity.Attributes["subject"] = "Customer Appointment 1";
serviceActivity.Attributes["scheduledstart"] = "25/03/2015 00:00 AM";
serviceActivity.Attributes["scheduledend"] = "26/03/2015 00:00 AM";
serviceActivity.Attributes["name"] = sID;
[/code]
I have already queried the equipment, systemuser and service entities to retrive the room to use, the teacher to use and the course to user respectively.
So I the ID and Logical names to hand. However should I be getting or recreating this data from/within the Activityparty entity?
I have tried these methods but they didn't work:
[code]
var customerParty = {
PartyId = new EntityReference(contact.LogicalName, _contactId)
};
Guid[] parties = { rID, uID } ;
serviceActivity.Attributes["resoures"] = parties ;
[/code]
I also have tried to use the EntityReferenceCollection and Relationship methods to associate them together but realised I needed the service appointment ID which wouldn't be created at that point.
If anyone could please advise on the best method for this, it would be much appreciated.
Sorry I do not have any error messages, it just processes the contact and account as normal but the service calendar is always empty.
Regards,
Steph