Adventures with Microsoft.Xrm.Tooling in Microsoft Dynamics 365 Customer Engagement

By | June 27, 2017

Microsoft.Xrm.Tooling.Connector library has been made available by the Dynamics CRM SDK team to make it easy to perform common operations, using direct functions that have been exposed for these.

Exploring the library in came in with a learning experience with subtle differences in how we were used to doing it earlier using API libs available.

Establishing Connection:

First things first, establishing connection. I had created a sample project a few months back that was perfectly working back then. However, when we tried to execute the same package again, we received the following error.

“Unable to Login to Dynamics CRMOrganizationServiceProxy is nullOrganizationServiceProxy is nullOrganizationWebProxyClient is nullOrganizationServiceProxy is nullOrganizationWebProxyClient is nullOrganizationServiceProxy is null”

Adventures with Microsoft.Xrm.Tooling in Microsoft Dynamics 365 Customer EngagementWe found an article by Aileen at, however make the requested change did not resolve the problem in our case.

Then to make sure we were working on the latest version of the libraries, we deleted the references to the following libraries

  • Xrm.Sdk.dll
  • Crm.Sdk.Proxy.dll
  • Xrm.Sdk.Deployment.dll
  • Xrm.Tooling.Connector.dll
  • IdentityModel.Clients.ActiveDirectory.dll

When you compile, it works just fine, but upon execution, you receive an error about missing reference to Microsoft.IdentityModel

Adventures with Microsoft.Xrm.Tooling in Microsoft Dynamics 365 Customer EngagementYou need to add references to the following to get this to work

  • Xrm.Tooling.Connector.dll
  • Xrm.Sdk.Deployment.dll
  • IdentityModel.Clients.ActiveDirectory.dll

Creating Records:

Traditionally, service.create has always required an object of Entity class as a parameter to be passed. XRM.Tooling, provides an additional way to pass the details of the record. You can now pass them as a dictionary of key/value pair

 

Setting field values for CrmDataTypeWrapper

In CRM 4 days we used to have the wrapper classes for data type that we needed to create object of set the values for. So a Boolean value could be set by creating an object of CrmBoolean() and then set the value of that object to true/false as desired. Looks like this system is back with the tooling connector.

Here is how to set the values for the various data types

1. Customer:

 2. String:

 3. Boolean:

 4. PickList:

5. Numeric:

6.  Money:

7. Guid/Unique Identifier:

 8. Lookup:

 

Batch Processing:

To ensure that all the requests are executed in a transaction so that even if a single request fails, the entire transaction rolls back, it provides a way for Batch Execution of requests as well.

The first step is to generate a Batch Id or Name

Next with every request submitted, please provide the batchid along

Though these requests get added to the batch, they have not executed right away. You need to make the call to execute the batch for the requests in the batch to be processed.

 If the response.IsFaulted == false that means the records have been successfully created successfully.

You get the results of the executed requests in the response object as can be seen below

Adventures with Microsoft.Xrm.Tooling in Microsoft Dynamics 365 Customer EngagementSpecial Requests:

Special requests like CloseQuote that earlier had to be executed through ExecuteRequest are now directly available as a function in the library that can be invoked directly

Note: The status must be greater than 3 but less than or equal to 7. You can also refer to the Microsoft’s blog for more info on this.

Click2Clone - Copy/clone Microsoft Dynamics CRM/Dynamics 365 records

Leave a Reply