CRM 2011: using OrganizationServiceClient to RetrieveMultiple AllColumns (retrieve all columns using pure WCF call)

First of all, it must be said that CRM 2011 .svc file does not give you all the things that you need for all kinds of operations with CRM 2011. The Reference.cs is missing lots of things related to CRM only(like OptionSetValue, EntityReference etc.). Either you can have your own custom class file with partial classes to those from Reference.cs classes OR you can add some additional lines in your Reference.cs to make it work.

Here we are adding the additional lines to the Reference.cs file(to view this, click on “Show All Files” button at the top of Solution Explorer in Visual Studio, then click on “Service References” -> “your Service reference to CRM” -> “Reference.svcmap” -> “Reference.cs“). Add these below two lines to the class “public partial class EntityCollection” in your “Reference.cs” file generated by the WFC service call file.

[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]

[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]  

 

Then you can use the below code to retrieve all the columns value with pure OrganizationServiceClient object.

QueryExpression query = new QueryExpression(){ EntityName = “systemuser” };

 query.Criteria = new FilterExpression();

query.Criteria.FilterOperator = LogicalOperator.And;

query.Criteria.Conditions = new ConditionExpression[] { new ConditionExpression() { AttributeName = “fullname”, Operator = ConditionOperator.Equal, Values = newstring[] { “name of the user” } } };

query.ColumnSet = new ColumnSet() { AllColumns = true, Columns = newstring[] { “”} };

 EntityCollection _entities = OrganizationServiceClient_Object.RetrieveMultiple(query);

 

Tricky part is : you have to set “Columns” to your QueryExpression columnset, even if you have set the “AllColums” to “true” to any dummy value. I have passed here “”. Then you have to let the EntityCollection class to know that there are something called “OptionSetValue” and “EntityReference” that it may need to talk with.

regards

joon

Advertisements

About Joon
quite ordinary man

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

%d bloggers like this: