Skip to main content

Sample Code to Check Connectivity with Dynamic 365 CE using Tooling Connector 

Ref: 
https://docs.microsoft.com/en-us/powerapps/developer/data-platform/org-service/quick-start-org-service-console-app
https://carldesouza.com/connecting-to-dynamics-365-using-crmserviceclient/


Retrieve Multiple Sample 

 
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Net;

namespace OrganizationServiceSample
{
    class Program
    {
        static void Main(string[] args)
        {

            string connectionString = "AuthType=OAuth;Username=demo1@*******.onmicrosoft.com;Password=********;Url=https://*******.crm4.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri=app://58145b91-0c36-4500-8554-080854f2ac97;LoginPrompt=Auto";
            CrmServiceClient conn = new CrmServiceClient(connectionString);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            IOrganizationService _orgService;
            _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

            if (conn != null && conn.IsReady)
            {
                QueryExpression query = new QueryExpression("account");
                query.ColumnSet.AddColumns("name");
                EntityCollection ec = _orgService.RetrieveMultiple(query);
                foreach (Entity a in ec.Entities)
                {
                    Console.WriteLine("Name: " + a.Attributes["name"] + " " + a.Attributes["name"]);
                }
            }
            else
            {

                Console.WriteLine("An error occurred: {0}", conn.LastCrmError);
                Console.WriteLine(conn.LastCrmException.Message);
                Console.WriteLine(conn.LastCrmException.Source);
                Console.WriteLine(conn.LastCrmException.StackTrace);
            }
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
    }
}

Comments

Popular posts from this blog

How to Integrate WhatsApp with Dynamics 365 Omnichannel – On Trial

How to Integrate WhatsApp with Dynamics 365 Omni Channel – On Trial Pre Requisites a.        Trail Environment with Customer Service Enabled, Preferably Netherlands as Location Ref : https://docs.microsoft.com/en-us/dynamics365/omnichannel/try-channels b.        Twilio Trial Account Ref : https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account#sign-up-for-your-free-twilio-trial Let’s Start the Configuration! Configuration: Dynamics 365 Channel Integration Framework - V2 1.        Go to dynamic 365 administration center via below link after logging to trial account https://port.crm4.dynamics.com/G/Applications/Index.aspx 2.        Make Sure Channel Integration Framework in Enabled, like in below screen shot else, configure it . By default, this should have enabled. Configuration: Omnichannel for Custo...

Delete record using JQuery and OData in Dynamics CRM 2011

function DeleteRecord(id, oDataSetName) {     var serverUrl = Xrm.Page.context.getServerUrl();     var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";     $.ajax({         type: "POST",         contentType: "application/json; charset=utf-8",         datatype: "json",         url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",         beforeSend: function (XMLHttpRequest) {             //results will be returned as JSON.              XMLHttpRequest.setRequestHeader("Accept", "application/json");             //HTTP method DELETE               XMLHttpRequest.setRequestHeader("X-HTTP-Method", "DELETE");         },         success: function (da...

How to attach refresh event on Dynamic CRM 2011 subgrid using Java Script / JQuery ?

// Attach the function OnFormLoad event function OnFormLoad() {     setTimeout("SubGridRefresh();", 2500 ); } function   SubGridRefresh() {     var subgrid = document.getElementById("subgridid");     if (subgrid.readyState != "complete") {         // recursive till the subgrid is loaded         setTimeout(SubGridRefresh, 1000);         return;     }     // if subgrid fully loaded       if (subgrid) {         // attach the name of the custom function to grid          subgrid .attachEvent("onrefresh", OnRefresh_SubGrid);          subgrid .control.add_onRefresh(OnRefresh_SubGrid);     } } function   OnRefresh_SubGrid() {     //custom code to execute     var entityid = Xrm.Page.data.entity.getId();     alert(entityid); } ...