private ArrayList RetrieveMultipleContacts(ICrmService crmService, Guid parentAccountId)
{ //variable initialization
ConditionExpression condition = new ConditionBLOCKED EXPRESSION;
FilterExpression filter = new FilterBLOCKED EXPRESSION;
QueryExpression query = new QueryBLOCKED EXPRESSION;
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
ColumnSet cols = new ColumnSet();
RetrieveMultipleResponse response = null;
ArrayList contacts = new ArrayList();
//Set the condition for retrieval
condition.AttributeName = "parentcustomerid";
condition.Operator = ConditionOperator.Equal;
condition.Values = new string[] { parentAccountId.ToString() };
//Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And;
filter.AddCondition(condition);
//Set the attributes needed to be returned. NOTE: The CRM Sdk has an erroneous example
//of how to set the attributes for retrieval.
cols.Attributes.Add("address1_line1"); cols.Attributes.Add("address1_line2"); cols.Attributes.Add("address1_line3"); cols.Attributes.Add("address1_city"); cols.Attributes.Add("address1_stateorprovince"); cols.Attributes.Add("address1_postalcode"); cols.Attributes.Add("address1_country"); cols.Attributes.Add("telephone1"); cols.Attributes.Add("fax");
//Set the properties of the QueryExpression object.
query.EntityName = EntityName.contact.ToString();
query.ColumnSet = cols;
query.Criteria = filter;
//Set the query for the request and set the flag to return
//dynamic entities
request.Query = query;
//retrieve the contacts
response = (RetrieveMultipleResponse)crmService.Execute(request);
foreach (BusinessEntity cont in response.BusinessEntityCollection.BusinessEntities)
{ contacts.Add(cont);
}
return contacts;
}