Hi Everyone,
I have a problem with ServiceAppointment filtration. I have a list of Service Appointments belong to many accounts. When I created ServiceAppointment I used following code
var newServiceAppointment = new ServiceAppointment { ServiceId = new EntityReference(CRMHelper.Service.EntityLogicalName, new Guid(serviceId)), Location = branchTitle, Resources = new ActivityParty[] { equipmentPartyResource }, ScheduledStart = Convert.ToDateTime(startTime), ScheduledEnd = Convert.ToDateTime(endTime), ScheduledDurationMinutes = scheduledDurationMinutes, Customers = new ActivityParty[] { accountPartyResource } };
where accountPartyResource and equipmentPartyResource defined as following
var equipmentPartyResource = new ActivityParty { PartyId = new EntityReference(Equipment.EntityLogicalName, new Guid(serviceEquipment.equipmentId)) }; var accountPartyResource = new ActivityParty { PartyId = new EntityReference(Account.EntityLogicalName, serviceAccount.Id) };
Now the problem is, I need to get all service activities belong to specific account or specific equipment.
I tried following FilterExpressions at QueryExpresion
QueryExpression targetServiceAppointmentQuery = new QueryExpression { EntityName = ServiceAppointment.EntityLogicalName, ColumnSet = new ColumnSet( "activityid", "subject", "serviceid", "location", "scheduledstart", "scheduledend", "customers", "statecode", "statuscode"), Criteria = new FilterExpression() { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression { AttributeName = "customers", Operator = ConditionOperator.Equal, Values = { new string[] { serviceAccount.AccountId.ToString() } } } } } };
Also I tired following formats
Criteria = new FilterExpression() { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression { AttributeName = "customers", Operator = ConditionOperator.Equal, Values = { new ActivityParty[] { accountPartyResource } } } } } //========================== Conditions = { new ConditionExpression { AttributeName = "customers", Operator = ConditionOperator.Equal, Values = {serviceAccount} } } //========================= Conditions = { new ConditionExpression { AttributeName = "customers", Operator = ConditionOperator.Equal, Values = {accountPartyResource} }
For all conditions I got following Error
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/.../Services:query. The InnerException message was 'Error in line 1 position 1147. Element 'schemas.microsoft.com/.../Arrays:anyType' contains data from a type that maps to the name 'schemas.microsoft.com/.../Contracts:Entity'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'Entity' and namespace 'schemas.microsoft.com/.../Contracts'.'. Please see InnerException for more details.
What I have to do?
Thanks in advance.