Connect To Dynamcis 365 Online using Power Shell


In this post I am going to show a basic example using CRM SDK through power shell to connect to CRM .

Power shell is so useful when you need to execute operations through SDK without Visual studio installed in your environment.

Code :


#navigate to SDK Folder

#execute script

#add crm snappin
Add-PSSnapin Microsoft.Xrm.Tooling.Connector

#Get Tool Alias
Set-Alias installUtil $env:windir\Microsoft.NET\Framework64\v4.0.30319\installutil.exe

#copy to gac
installUtil /u Microsoft.Xrm.Sdk.dll;

#Initialize connection
$CRMConn =Get-CrmConnection –ConnectionString "Url=; Username=###; Password=###; authtype=Office365"

#Get Organization service proxy
$orgService=$CRMConn.OrganizationServiceProxy ;

#construct query
$query="<fetch mapping='logical' distinct='false' aggregate='true'>
<entity name='account'>
<attribute name='account' alias='recordcount' aggregate='count'/>

#Create Query expression

$queryExp = New-Object -TypeName Microsoft.Xrm.Sdk.Query.FetchExpression -ArgumentList $query ;

#Get Results

#Extract Count

Write-Host $countItem.Value

Connect to Dynamics 365 using C# SDK


I am going to show  in a few steps how to create an organization service proxy for dynamics 365 .

Steps :

  • Create a new project in visual studio
  • Add nuget package :"Microsoft.CrmSdk.CoreAssemblies"
  • Add the following piece of code

CrmServiceClient conn = new CrmServiceClient("Url=; Username=test; Password=test; authtype=Office365");

// Cast the proxy client to the IOrganizationService interface.
var _orgService = (Microsoft.Xrm.Sdk.IOrganizationService)conn.OrganizationWebProxyClient != null ? (Microsoft.Xrm.Sdk.IOrganizationService)conn.OrganizationWebProxyClient : (Microsoft.Xrm.Sdk.IOrganizationService)conn.OrganizationServiceProxy;

Quick View Form and sub grid Issue in Dynamics 365


Intro :

I encountered a problem while working with quick view forms having sub grids.

The quick view form is meant to display the account details upon selecting an account on lookup in custom entity form.


Quick view form has sub grid displaying related record to account such as cases and opportunities , the problem occurs whenever you change the select account , all the details are updated to reflect the new selected account except the sub grids .

 They keep displaying the related records to the old one.

Fix :

  1. Add on change event handler on the account lookup
  2. Include the following piece of code in your java script function

var quickViewControl = Xrm.Page.ui.quickForms.get("your quick view form name");
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {