Using the RetrieveMultiple Method in Microsoft Dynamics CRM 4.0


// Set up the CRM Service.

CrmAuthenticationToken token = new

CrmAuthenticationToken();

// You can use enums.cs from the SDK\Helpers folder to get

the enumeration for AD Authentication.

token.AuthenticationType = 0;

token.OrganizationName =”AdventureWorksCycle”;

CrmService service = new CrmService();

service.Url

=”http://<servername&gt;:<port>/mscrmservices/2007/crmservice.

asmx”;

service.CrmAuthenticationTokenValue = token;

service.Credentials =

System.Net.CredentialCache.DefaultCredentials;

// Create the ColumnSet indicating the properties to be

retrieved

ColumnSet cols = new ColumnSet();

// Sets the ColumnSet’s Properties

cols.Attributes = new string [] {“fullname”, “contactid”};

// Create the ConditionExpression

ConditionExpression condition = new ConditionExpression();

// Set the Condition for the Retrieval to be when the

contact’s address’ city is Sammamish

condition.AttributeName =”address1_city”;

condition.Operator = ConditionOperator.Like;

condition.Values = new string [] {“Sammamish”};

// Create the FilterExpression

FilterExpression filter = new FilterExpression();

// Set the Filter’s Properties

filter.FilterOperator = LogicalOperator.And;

filter.Conditions = new ConditionExpression[] {condition};

// Create the QueryExpression Object

QueryExpression query = new QueryExpression();

// Set the QueryExpression Object’s Properties

query.EntityName = EntityName.contact.ToString();

query.ColumnSet = cols;

query.Criteria = filter;

// Retrieve the Contacts

BusinessEntityCollection contacts =

service.RetrieveMultiple(query);

 

%d bloggers like this: