How To Retrieve Data From CRM 4.0

5:32 PM

Dynamic crm - how to retrirve data from crm 4.0
CRM 4.0 - Retrieve data crm
After we created Connection for CRM 4.0 , now we will try in a simple way how to retrieve data from CRM 4.0. It is very simple. there is two way how to retrieve data from crm, first, use query by attribute, it like like select in sql with the only one condition. second, use query expression, it like selet in sql with multy condition. and now we are going to try using query expression.
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

You Might Also Like

0 comments