Using the RetrieveMultiple Method in Microsoft Dynamics CRM 4.0

Posted: January 20, 2009 in Uncategorized
Tags:

// 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);

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s