Azure: Copy Data from D365 CE to Azure SQL Database using Azure Data Factory


Ajit Patra's avatarAjit Patra

In this blog post, we’ll see how to copy data of an entity “Contact” in D365 CE to Azure SQL Database. Let’s follow the below steps to see it in action.

  • Login to Azure portal.
  • Create Azure SQL Database where we need to copy the data. Click Create a resource –> Databases –>  SQL Database

  • Give a unique name to the database. Click on server field to create a Azure SQL Server. Give a unique name to the Azure SQL server, username and password for logging in. Click Select.

  • Make sure the Azure SQL Server just created is selected as Server while creating the Azure SQL Database –> Click on Create.

  • Connect to the Azure SQL Server just created using SSMS. Here, we’ll have to add machine IP or range of IP address after clicking Connect.

  • After signing in using Azure credential, select range…

View original post 366 more words

Above and Under operator to query hierarchical data in Dynamics 365


above and under were the 2 new operators introduced with Dynamic CRM 2015.

Let us see some of the examples.

Suppose I have the following hierarchy defined, wherein User 2 is manager of user Nishant Rana who in turn is manager of User 1.

And following are the contacts record owned by them.

In context of user Nishant Rana, if I apply Under operator, we’d get the following result

Only the records owned by child

And for Not Under

All the records owned by the user and its manager(s) or parent.

Now we do not have the Above operator in Advanced Find

So, using our favorite tool Fetch XML Builder, the above operator shows only the records owned by the parent(s) of current user.

We also have Above or equal, Under or equal operator which aren’t there in Advanced Find.

Hope it helps..

A quick find filter cannot have any child filters exception in Dynamics 365 CE


Today afternoon we started getting the below error in the lookup dialog box for customer and contact.

error

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: A quick find filter cannot have any child filtersDetail:

<OrganizationServiceFault xmlns:i=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts”&gt;

<ActivityId>a5d85309-b57b-4265-b54e-afd09bfeeddc</ActivityId>

<ErrorCode>-2147217118</ErrorCode>

<ErrorDetails xmlns:d2p1=”http://schemas.datacontract.org/2004/07/System.Collections.Generic”&gt;

<KeyValuePairOfstringanyType>

<d2p1:key>ApiExceptionSourceKey</d2p1:key>

<d2p1:value xmlns:d4p1=”http://www.w3.org/2001/XMLSchema&#8221; i:type=”d4p1:string”>Plugin/Microsoft.Crm.Common.ObjectModel.AccountService</d2p1:value>

</KeyValuePairOfstringanyType>

<KeyValuePairOfstringanyType>

Searching for this in the internet we found that mostly the users that are in Microsoft Dynamics 365Version 1710 (9.1.0.643) online are getting this error.

We as suggested raised the support ticket for this in the evening. However strangely enough after 2-3 hours when we are checking this error it is not coming anymore.


We had created one trial instance which was also having the same issue and it has been fixed there. It looks like product team have deployed some kind of fix for it in the background.

Hope it helps..

Getting logged in user roles in client side in Dynamics V9.0


Debajit's avatarDebajit's Dynamic CRM Blog

You may be asking? Why this mundane post? After all we have been here close to 8 years since 2011 released and we have millions of time retrieved it using

So what’s the fuss in it?

So if you are working on CRM version below 9.0, then it’s no fuss. But if you are working on V9.0 and above, may be this is an interesting read for you.

Xrm.Page is deprecated.

So what’s the other way. Well you need to do it the V9.0 way. Below is the code to do the same.

And the userRoles variable here contains the list of GUID’s of the roles the user have. Wasn’t that easy?

For e.g – not only you can get the security roles but also the privilege id’s for all the security roles associated with the user.

Debajit Dutta
(Dynamics MVP)
For consultation/ training visit http://www.xrmforyou.com or reach out to…

View original post 3 more words

Sample code to delete instance using Online Management API in Dynamics 365 Customer Engagement


Sharing a sample code that can be used to delete the instance in Dynamics 365 CE using Online Admin API.

Read the previous post for more details

We basically need to get the instace id and use the HTTP Delete to achieve this

https://docs.microsoft.com/en-in/rest/api/admin.services.crm.dynamics.com/Instances/DeleteInstance

Production instance needs to be converted to Sandbox before it can be deleted else we’d get the operation not supported error.

The sample code :-

private static void Main(string[] args)
{
var authContext = new AuthenticationContext(Authority, false);
var credentials = new UserCredential(UserName, Password);

// Get the token
_authResult = authContext.AcquireToken(Resource, ClientId, credentials);

Task.WaitAll(Task.Run(async () => await DeleteInstance()));
}
private static async Task DeleteInstance()
{
var httpClient = new HttpClient
{
BaseAddress = new Uri(Resource),
Timeout = new TimeSpan(0, 2, 0)
};

httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
_authResult.AccessToken);

var retrieveResponse =
await httpClient.DeleteAsync("/api/v1.1/Instances/{instanceGuid}/Delete");

if (retrieveResponse.IsSuccessStatusCode)
{
var jRetrieveResponse =
retrieveResponse.Content.ReadAsStringAsync().Result;

}
}

Hope it helps..

Sample Code to retrieve instances using Online Management API in Dynamics 365 Customer Engagement


With version 9.0 of Dynamics 365 CE we now have Online Admin API that supports the following operations like Create, Retrieve, Delete, Backup and Restore instances. The user needs to have the Global Administrator or Service Administrator role in the Office 365 tenant to perform these operations.

As a first step we need to register the application with Azure Active Directory.

https://nishantrana.me/2016/11/13/register-a-dynamics-365-app-with-azure-active-directory/

and get the values for

Client Id and Authority.

Get the Service URL here

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/online-management-api/get-started-online-management-api#service-url

Sharing a sample code which can be used to retrieve all the instances in a specific tenant.

The sample code: –


public class MySampleApp
{

private const string Resource = "https://admin.services.crm.dynamics.com/";

// username and password
private const string UserName = "username.onmicrosoft.com";
private const string Password = "password";

// client id and authority of the application registered
private const string ClientId = "b2c5028d-57e6-4df7-9940-3243214948b";
private const string Authority = "https://login.microsoftonline.com/3432432e2-5fbe-4b78-a55a-bcb342d4f859/";

private static AuthenticationResult _authResult;

private static void Main(string[] args)
{
var authContext = new AuthenticationContext(Authority, false);
var credentials = new UserCredential(UserName, Password);

// Get the token
_authResult = authContext.AcquireToken(Resource, ClientId, credentials);

Task.WaitAll(Task.Run(async () => await GetInstances()));
}

private static async Task GetInstances()
{
var httpClient = new HttpClient
{
BaseAddress = new Uri(Resource),
Timeout = new TimeSpan(0, 2, 0)
};

httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
_authResult.AccessToken);

var retrieveResponse =
await httpClient.GetAsync("/api/v1/instances");

if (retrieveResponse.IsSuccessStatusCode)
{
var jRetrieveResponse =
retrieveResponse.Content.ReadAsStringAsync().Result;

var result = JArray.Parse(jRetrieveResponse);
foreach (var data in result)
Console.Write("Id " + data["Id"] + "\nUnique Name " + data["UniqueName"]);
}
}
}

Result: –

The other properties: –