Vignesh Subramanian
Vignesh Subramanian

Reputation: 7289

How to get list of items in an entity using DiscoveryService in Dynamics CRM 2016?

I am trying to get the list of contacts using the DiscoveryServiceClient in CRM 2016 on-prem

I added service reference and created an object, but I am not sure on what method I should be using to get the list of Entity items

                    CRMService.DiscoveryServiceClient client = new CRMService.DiscoveryServiceClient();
                    client.Open();
                    var query = new QueryExpression();
                    query.EntityName = "Contact";

                    query.ColumnSet = new ColumnSet { AllColumns = true };
                    var coll = client.RetrieveMultiple(query);

                    Console.WriteLine("Retrieved {0} entities", coll.Entities.Count());
                    foreach (var item in coll.Entities)
                    {
                        Console.WriteLine("Contact: " + item);
                    }
                    client.Close();

When I used the above code it says

DiscoveryServiceClient does not contain a definition for RetrieveMultiple

I also tried using the below code

QueryExpression qe = new QueryExpression();
                    qe.EntityName = "contact";
                    qe.ColumnSet = new ColumnSet();
                    qe.ColumnSet.Columns.Add("emailaddress1");
                    EntityCollection ec = organizationProxy.RetrieveMultiple(qe);
 foreach (Entity act in ec.Entities)
                    {
                        Console.WriteLine("account email:" + act["emailaddress1"]);
                    }

This loads fine, but all values are null inside the items

Upvotes: 1

Views: 246

Answers (1)

Daniel König
Daniel König

Reputation: 61

Is there a special need for you to use the DiscoveryServiceClient? If this is a job or so, you should/could use the IOrganizationService to retrieve your EntityCollection.

Here is a little Link, that might help you: https://learn.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg328029(v=crm.8)

Upvotes: 1

Related Questions