Retrieve / retrieve records from DYNAMIC 365 crm using C # code

  • Problem 1:

    I am new to MICROSOFT DYNAMIC CRM 365. I have several tables with my CRM, for example (Account, Customer). I want to get all the data from a table account.

Below is an example of the connection code: (not sure if this is correct or not, but I get an exit message that is connected to CRM)

public void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri) { try { ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = UserName; credentials.UserName.Password = Password; Uri serviceUri = new Uri(SoapOrgServiceUri); OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null); proxy.EnableProxyTypes(); _services = (IOrganizationService)proxy; Response.Write("Connected to CRM \n"); } 

I need all the data to be retrieved on a button click event.
The result should be: the result is "select * from ABC" ;

  • Problem 2:

if possible, suggest how to retrieve the records using the specified column name.
The output should be: the result is "select * from ABC where ColumnName="test" ;

0
source share
2 answers

Getting a list of all entities in a list

  var allEntities = **GetEntities(_service);** foreach (var Entity in allEntities) { ddlEntityName.Items.Add(Entity.LogicalName); } 

// Function with a single parameter (service as a parameter)

// This will call the table / object name, like ACCOUNT, CONTACT from Microsoft Dynamic CRM

 public Microsoft.Xrm.Sdk.Metadata.EntityMetadata[] GetEntities(IOrganizationService organizationService) { Dictionary<string, string> attributesData = new Dictionary<string, string>(); RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest(); RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse(); metaDataRequest.EntityFilters = EntityFilters.Entity; XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas(); myReaderQuotas.MaxNameTableCharCount = 2147483647; // Execute the request. metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest); var entities = metaDataResponse.EntityMetadata; return entities.OrderBy(x => x.LogicalName).ToArray();//to arrange in ascending order } 
+1
source

How about a query expression?

This is your request:

 Select * from ABC where ColumnName="test"; 

And this is QueryExpression :

 QueryExpression query = new QueryExpression() { EntityName = Contact.EntityLogicalName, ColumnSet = new ColumnSet("address1_telephone1"), }; 

to fix the request, here's how:

 DataCollection<Entity> entityCollection = _services.RetrieveMultiple(query).Entities; // Display the results. foreach (Contact entity in entityCollection) { Console.WriteLine("my test: {0}", entity.address1_telephone1); } 

Hello

0
source

All Articles