Saturday, May 16, 2020

Retrieve Multiple records Using GUID

     
 Retrive Multiple using GUID of the record is some thing different from normal crietra like retrieve with first name last name.

In retrive multiple criteria we have to use   new ConditionExpression like below


RetrieveAccountId.Criteria.AddCondition(new ConditionExpression("accountid",   ConditionOperator.In, accountId));



Full code is followed for retrieving multiple records, displaying those retrieved records data using for each


            Guid[] accountId = new Guid[1];
            accountId[0] = new Guid("475b158c-541c-e511-80d3-3863bb347ba8");

            var retrieveAccountId = new QueryExpression();
            retrieveAccountId.EntityName = "account";
            retrieveAccountId.ColumnSet = new ColumnSet(true);
            retrieveAccountId.Criteria.AddCondition(new ConditionExpression("accountid",   ConditionOperator.In, accountId));
            EntityCollection AccountCollection = orgService.RetrieveMultiple(retrieveAccountId);
            foreach (var account in AccountCollection.Entities)
            {
                Console.WriteLine("Account Name {0}", account["name"]);
            }



Thats it..

Connect with CRM using console Application with SOAP service



1. Create a console application in VS.

2. Download CRM SDK from http://xrm.tools/SDK

3. Inside the Project Reference folder Add these reference from Downloaded SDK's reference folder also you have other references in your local system you can add it by right clicking the reference folder selecting add reference



4. Code is below.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;

namespace ConsoleConnectToCRMUsingWebApi
{
    class Program
    {
        static void Main(string[] args)
        {
            #region credentials
            string SoapOrgServiceUri = "https://Orgname.api.crm.dynamics.com/XRMServices/2011/Organization.svc";
            ClientCredentials credentials = new ClientCredentials();
            credentials.UserName.UserName = "UserName";
            credentials.UserName.Password = "Password";
            #endregion

            Uri serviceUri = new Uri(SoapOrgServiceUri);
            OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
            proxy.EnableProxyTypes();
            IOrganizationService orgService = (IOrganizationService)proxy;


            Guid accountId = new Guid("475b158c-541c-e511-80d3-3863bb347ba8");
            Entity entity = orgService.Retrieve("account", accountId, new ColumnSet("name"));
            Console.WriteLine("account name: {0}", entity["name"]);
            Console.ReadLine();



        }
    }
}

5. Output will be look like




Thank you!