How To Retrieve Data From CRM 4.0
5:32 PMCRM 4.0 - Retrieve data crm |
Step 1.
we make new class with the name crmclass or whatever else and begin make capacity for recover information crm
using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.Sdk.Metadata; using Microsoft.Crm.SdkTypeProxy.Metadata; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace CRMTutorial { class CRMClass { public BusinessEntityCollection getallrecod_byexpression(CrmService _crmservice, string _entityname, string[] _columnset) { QueryExpression q_expression = new QueryExpression(_entityname); q_expression.ColumnSet = new ColumnSet(_columnset); RetrieveMultipleRequest request = new RetrieveMultipleRequest(); request.Query = q_expression; request.ReturnDynamicEntities = true; RetrieveMultipleResponse response = (RetrieveMultipleResponse)_crmservice.Execute(request); BusinessEntityCollection returnentities = response.BusinessEntityCollection; return returnentities; } } }
Step 2.
just call the function in main program
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.Sdk.Metadata; using Microsoft.Crm.SdkTypeProxy.Metadata; using System.IO; namespace CRMTutorial { class Program { static void Main(string[] args) {
//create object from crm class
CRMClass mycrmclass = new CRMClass();
BusinessEntityCollection entities = mycrmclass.getallrecod_byexpression(service, "your entity name", new string[] { "your attribute name" }); if (entities.BusinessEntities.Count > 0) { foreach (DynamicEntity entityname in entities.BusinessEntities) { string attributetoshow= entityname.Properties["your attribute name"].ToString(); } } } } }
finish :)
thanks for reading
0 comments