Friday, 13 July 2018

console application to connect to dynamics CRM



we have used the dynamics 365 Extension to create this console application .which can be downloaded from the following link :
https://marketplace.visualstudio.com/items?itemName=JLattimer.DynamicsCRMDeveloperExtensions#overview

Note : IOrganisation service has been deprecated and will be removed in future after 2019.

in app.config

add this inside the <connectionStrings>

    <add name="CRMConnectionString" connectionString="Url=https://junealdous.crm8.dynamics.com; Username=aldous@junealdous.onmicrosoft.com; Password=pass@123; AuthType=Office365;" />


CODE:

//This code will create a account name "New Account"


using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace CSharpConsole2
{
    class Program
    {
        private static CrmServiceClient _client;

        public static void Main(string[] args)
        {
            try
            {
                using (_client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRMConnectionString"].ConnectionString))
                {
                   
                    IOrganizationService crmService = _client.OrganizationServiceProxy;

                    Entity acc = new Entity("account");
                    acc["name"] = "New Account";
                    crmService.Create(acc);
                 



                }
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                string message = ex.Message;
                throw;
            }
        }
    }
}

No comments:

Post a Comment

How to Call an Action through Power Automate(MS Flow)

  Introduction As Microsoft is providing us more flexibility with Power Automate (MS Flow), recently we found that now we can call the Actio...