Thanks To all my blog readers and Microsoft for the Microsoft Most Valuable Professional Award 2018-2019

A big thank you note to all my blog readers without whom this has not been possible. It’s been a great journey so far and undoubtedly it’s my blog which has helped me in this.

Big thanks to Microsoft as well and once again thanks to everyone for every read of my blog. I hope it has been useful to you as much as it has been useful to me.

Keep reading, keep learning, keep sharing.



Debajit Dutta

(Dynamics MVP)

For training/ consulting/ utilities – please visit our website – or write to us at


CRM on-premise to Sharepoint online integration–Common obstacles faced and their work-around.

Before I start writing the details, first let me tell you why this blog. After all this is so nicely explained in the following link –

Well, the above link contains all the steps you need to set-up server-server integration between Dynamics On-Prem and Sharepoint online. But still from my personal experience I find that customers find it great difficult to set this up. This is mainly because they get some error while executing a step or because some pre-requisites are not there and they are not mentioned in the technet link as well.

The main intention of this post is to rectify all those errors, identify all the dependencies and work your way to glory.

So let’s identify the dependencies first.

Dependency 1 : Dynamics should be ADFS configured and accessible over the internet.

I am not going over the topic again on how to do it. Greatly explained here – and in so many other blogs.


Dependency 2: Microsoft Dynamics 365 Hybrid Connector should be configured.

Believe me, from my personal experience I find many clueless about this. Well you no longer need to. You just need to verify here if Dynamics 365 Hybrid connector subscription is available and commissioned.

To do this:

  • Login to using the Office 365 admin credentials for your SP online tenant.
  • Open the Office 365 admin screen
  • Go to Billing –> Purchase Services


  • Expand the section Dynamics 365 Suite. Usually its expanded. If not expand it.



    • Below is the screen you get. As of now its free but the way it shows up I believe it will be chargeable some time soon Smile


    • Enter you credit card number and then click on Place Order. Don’t worry, you won’t be charged for this. You are all set and done.


Dependency 3: Connect to Microsoft Online through PowerShell.

Now this can become tricky. The technet documentation says – You need to have Azure Active Directory powershell modules. And the link redirects you to a page where it asks you to install the module using Powershell command prompt – Install-Module MsOnline

The moment you do this step, you get an error like the one below.

install-module : The term ‘install-module’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:1 char:1
+ install-module MSOnline +
+ CategoryInfo          : ObjectNotFound: (install-modele:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


Well to successfully accomplish this, you need to complete both the required steps.

  1. Microsoft Online Services Sign-In Assistant for IT Professionals Beta – select the appropriate download. It may ask you to restart the machine for the changes to take effect. Please do the same.
  2. Now also if you run the install-module command, it would fail. The reason is install-module command is available from Powershell v5.0 and above. So you need to update your powershell as well. To do this, download the necessary installer depending on your server/ 64 or 32 bit machine, from the below Url.

Again machine restart is required.

Now open powershell as administrator and then try to install the module MSOnline. It will now download the same from Nuget.


Requirement 4: X.509 Digital certificate

Well this is the simplest but again it can give you some errors which would be difficult to find out. The first question is – which certificate do I need to use.

Well, the easiest answer is, you can use – “An x509 digital certificate issued by a trusted certificate authority that will be used to authenticate between Dynamics 365 (on-premises) and SharePoint Online. If you are evaluating server-based authentication, you can use a self-signed certificate.”

So we can basically re-use your CRM certificate or ADFS certificate. All you should take care is while exporting the certificate, it should be exported along the private key.



* Export all extended properties should be checked.



You will be asked to provide a password. Keep this password as you will need this later.



Once the file is exported, import it in the personal store of the machine where deployment manager is installed.

The technet article asks you to execute the below command.

$CertificateScriptWithCommand = “.\CertificateReconfiguration.ps1 -certificateFile c:\Personalcertfile.pfx -password personal_certfile_password -updateCrm -certificateType S2STokenIssuer -serviceAccount contoso\CRMAsyncService -storeFindType FindBySubjectDistinguishedName”

The service account is important here in the above statement. Whatever service name you provide here, that should have access to the private key of the certificate. To do that, you need to provide permission to the private key from the certificate console.
Click on Manage Private Keys and give the service account user full permission on the certificate.
After completing all the above steps, while connecting to your CRM, you may receive the 401 - Un-authorized error in Powershell. For this follow the below steps.

Open registry editor


    1. Right-click Lsa, point to New, and then click DWORD Value.
    2. Type DisableLoopbackCheck, and then press ENTER.
    3. Right-click DisableLoopbackCheck, and then click Modify.
    4. In the Value data box, type 1, and then click OK.

Re-open powershell. It should work.

The commands I am not repeating from the technet article since they work just fine.
Hope this helps!

Debajit Dutta

(Dynamics MVP)

For training/ consulting/ utilities – please visit our website – or write to us at



{Quick Tip} Manage your Entity Forms when your CRM is exposed to Web and Mobile App

Spoiler alert! Unlike other blogs, I am not going to update you about any new feature. Rather I am going to share my project experience in handling multiple forms designed for your Web and Mobile layouts.


You have exposed you CRM recently to Mobile Apps. When you expose your CRM to Mobile Application development, in most of the scenarios you would end up designing separate forms. Let’s take the example of Account entity. Say you have designed two forms

  • Account Web Form – This form is displayed to users while accessing CRM to Web
  • Account Mobile Form – Form displayed to users while browsing CRM on Mobile

And you have your users who will just access CRM through desktop and then some users accessing CRM through both Desktop and mobile.


So now the implementation

First of all, as I have been across client locations, I find that some consultants still assume that to expose a form in mobile, we need to create a form of type = ‘Mobile Express’. Mobile express forms were required for previous Dynamics app – Dynamics CRM Phone express. For the current version of Mobile App for Dynamics, Form Type = Main would work just fine

So what is the next step? We create a new form of type Main, this time specifically for mobile and put in only the fields required for Mobile as per the requirement. But wait, we have another form already exposed for the desktop. So how do we handle this.

  • Create a new security. Let us name it here – “Mobile User Security Role”. The privileges for this security role is optional and depends on your requirements.
  • Assign the security to users who need to access CRM on mobile.
  • In the Form order for Main Form set, set the Mobile form at the top of form order.


  • The next step is to leverage the role based forms. Expose the Account – Mobile form to only users with Mobile User Security Role.


Uncheck the “enabled for fallback” checkbox as well.

Save an publish your customizations.

All set and done. Now this works very well for users who does not use desktop and manages through mobile (hardly the case) and users not exposed to mobile platform. However the issue is for a user who has access to mobile and desktop version. They now see two forms and the mobile form starts showing up in the desktop as well as it is highest level in the form order as well.

The last step here is to switch the mobile if it loads on desktop. The simple piece of client side script would just work fine when put in form load of the mobile form.

function SwitchToDefaultFormForWebVersion(){

        var _defaultFormName = "account web form";

        var _isMobileClient = Xrm.Page.context.client.getClient() == "Mobile";

        if (!_isMobileClient) {

            var availableForms = Xrm.Page.ui.formSelector.items.get();

            var currentForm = Xrm.Page.ui.formSelector.getCurrentItem();

            if (currentForm != null) {

                var currentFormLabel = currentForm.getLabel();

                if (currentFormLabel.toLowerCase() == _defaultFormName)



            for (var i = 0; i < availableForms.length; i++) {

                if (availableForms[i].getLabel().toLowerCase() == _defaultFormName) {






Please remember that form navigation script is not supported on mobile. Hence first I am making the check if the client is Mobile.

Well there you go. Everything is up and running for you now.


Hope this helps!


Debajit Dutta

(Dynamics MVP)

For training/ consulting/ utilities – please visit our website – or write to us at

Open Lookup Dialog Programmatically using Xrm.Utility–Dynamics V9.0

This one feature that I am going to pen down here, personally I have longing for it quite sometime now.

So before going into the HOW part of it, let’s understand the why part of it? When do I need show a Lookup dialog Programmatically? Well the answer is, numerous occasions. Like if you need to throw up a lookup dialog on change of field on the form OR you needed to throw the lookup dialog on click of a button on a web-resource.

All this time, we have achieved this but not in a supported way. Probably we may have ended up using Xrm.Internal.openDialog or some method of Mscrm.Internal namespace. But all these are unsupported and mere workaround to this perennial problem.

Well, no more messing around. Microsoft has finally brought in the Xrm.Utility.lookupObjects.

So let’s see how it works.

Let’s take a not so good example here. Let’s say whenever the account country is US, primary contact is mandatory and the user is thrown a lookup dialog of contacts from where he needs to select the Primary Contact. below if the function registered on change of country field

function changeOfCountry(e) {
    var formContext = e.getFormContext();

    if (formContext.getAttribute("address1_country").getValue() == "US") {
var lookupOptions = {};
        lookupOptions.allowMultiSelect = false;
        lookupOptions.defaultEntityType = "contact";
        lookupOptions.entityTypes = ["contact"];


            function (result) {
                if (result != undefined && result.length > 0) {
                   var selectedItem = result[0];

                    formContext.getAttribute("primarycontactid").setValue({ entityType: selectedItem.entityType, id:, name: });
            function (error) { }

Focus on the highlighted lines starting from top. The first is the lookupOptions paramter. Since we are going to open a contact, I have specified defaultEntityType and entityTypes both to contact.

Also you can set the defaultViewId and the viewIds property to show the default view to use and views to be available in the view picker respectively

For a complete set of the properties of lookupOptions refer to Microsoft Documentation.

As soon as the method is executed, the below dialog opens up


Cool isn’t it? Now half of the job is done. But how about getting the selected record back. Well this method does not disappoint you here either.

The success callback function returns the selected item as you can see from the code above.

It has properties of entityType, id and the name which you can use to set the look up field of any other type. Here I have used the same to set the value of primarycontactid field of the account record.

Such a huge sigh of relief for me.

Hope this helps!


Debajit Dutta

(Dynamics MVP)

For training/ consulting/ utilities – please visit our website – or write to us at

{Dynamics V9.0}–Show alert/ confirm/ error in Modal style with new Client API in Dynamics Version 9.0

Working currently on a client engagement on the latest Dynamics version (v9.0) and hence got a chance to the new introduced Client API’s with version 9.0.

For starters, the Xrm.Page has been deprecated with version 9.0 and a completely new set of API’s have come up with version 9.0 along with host of new features.

For a list of deprecated API’s –

So coming back to the requirement here, if you have worked on Client API’s, chances are more that you have worked with Xrm.Utility namespace. Showing alerts/ confirmations/ opening entity forms/ webresources – what not can we do with the namespace.

However there was a problem. Xrm.Utility.alertDialog/ Xrm.Utility.confirmDialog still used to leverage the window.alert/ window.confirm for a web client. The result is – customer always complained about the look and feel of the pop-up. And also the ability to customize the contents of the same.

Well no-more. Now you have complete control on these. Excited? Let’s explore together.

1. Xrm.Navigation.openAlertDialog

The previous Xrm.Utility.alertDialog has been replaced with this new API. So let’s  see how to open an alert dialog using this function.

var message = { confirmButtonLabel: "Test Button", text: "New alert API Test" };
var alertOptions = { height: 150, width: 280 };
Xrm.Navigation.openAlertDialog(message, alertOptions).then(
    function success(result) {
        console.log("Alert dialog closed");
    function (error) {

Wonderful isn’t it? You get an option to even choose the button text. And even more is the flexibility to choose the height and width.

Now let’s see how it renders.


Such a relief to the eye from the previous versions. And what a relief to the customers!


2. Xrm.Navigation.openConfirmDialog

This is the new version of the previous API – Xrm.Utility.confirmDialog.

Let’s see how to invoke it

var confirmStrings = { text:"This is a confirmation.", title:"Confirmation Dialog", subtitle: "test subtitle", "cancelButtonLabel": "Test Cancel", confirmButtonLabel: "Test Confirm" };
var confirmOptions = { height: 200, width: 500};
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
function (success) {   
    if (success.confirmed)
        console.log("Dialog closed using OK button.");
        console.log("Dialog closed using Cancel button or X.");


As you can see, you can put title/ subtitle/ text/ cancelButtonLabel/ confirmButtonLabel and also the height and width. The complete rendering of the pop-up is now in your hands.

And now let’s see how it looks.



3. Xrm.Navigation.openErrorDialog

Well this is something new here. Let’s see first the nomenclature of this function. As per Microsoft Documentation



The important thing here is errorOptions. So let’s first explore that.

What are the parameters here:

  • details: Any custom details you want to include in the error. If you specify this – “Download Log File” button would show up.
  • errorCode: Now this is wonderful. If you specify this, the message for the corresponding errorCode is retrieved from the server and shown.
  • message: this is the custom message that you want to display in the dialog.

var errorOptions = {message: "Custom Error Message", details: "Inner exception details"};
    function (success) {
    function (error) {

Below is the UI I get. strangely enough, the custom error message is not displayed. However if I download the log file, the details are in the log file.



Log file:



Hope this helps!


Debajit Dutta

(Dynamics MVP)

For training/ consulting/ utilities – please visit our website – or write to us at

{Thank You Note} It’s 50 not out and counting for our SharePoint Attachment Uploader and Metadata Manager tool

A big thanks to all our customers who has helped us in our journey so far. Without your support, we would not have been able to reach this far.

A new version of the tool awaits with new feature and UI and is going to be released soon.

Thanks a lot for your support



Video Link –


To know how we can help you, write to us at or visit our website –

{Quick Tip} Pass a custom single/ collection of objects with Custom Properties as Output parameter from Actions in Dynamics 365

One of the great features that got introduced with Dynamics 2013 was Actions. With time more & more improvement came in with Actions and today Actions are one of the most powerful extending features in Dynamics.

And here I was designing actions for a client. Coming quickly to the requirement, the client had an action where they were determining complex business logic in the action with some input parameters and then based on the calculation, they need to pass back multiple values back to the invoker of the action.

There can be multiple ways to do this and one can be pass each of these values of Output Parameters. But that did not go well with the customer as around 15 properties needed to be returned from the action.

So the client developer came up with a DataModel class something similar to this.


internal class OutputClass


public string Property1{get;set;}




public decimal Property15{get;set;}



Nothing fancy. all the developer was doing was mapping the properties of this class and then the object back to the invoker of the action. But how to do it? Does Action allow custom object types to be passed as return parameters. Well,direct answer is No. But there are ways.

  • serialize the object into JSON and put the output JSON string through a string Output parameter – Didn’t go well with the customer. Has to abandon
  • serialize the object into XML and put the output XML string through a string Output parameter – Didn’t go well with the customer. Has to abandon again.


What I am left with then? We all know that it supports entity and entitycollection as output parameter types. But how do I use them to accomplish my goal here. The customer is not willing to create any Entity specifically for this.

Well a bit of trial and finally I achieved the below as workaround.

1. Passing a single Object back.

Well for this I used the entity parameter and just selected the Account Entity as Entity Type. You can use any Entity here. Does not matter.



In the plugin registered on the Action step, after calculating all the properties, I am setting the Output parameter like this.

var ent = new Entity("account");
ent["mytestproperty"] = "Test Name";
ent["mytestproperty2"] = 1;

ent["myentityreference"] = new EntityReference("contact", Guid.NewGuid());

context.OutputParameters["EntityParam"] = ent;

Observe carefully the code above. I am just creating an entity at runtime of type “account”. I don’t need to even specify the Guid. And then I can just put my custom property names for the entity and assign values of entity type – string/ int/ decimal/ entityreference etc.

None of these properties are present in the account entity. The trick is CRM framework does not validate the fields of the entity. So you can just return the entity object back with your own parameters. Cool trick. Isn’t it.

And below is the output received by the invoker of the action.



2. Passing Multiple Objects of Different type

For this, I used the entity collection as Output parameter



And below is the code to set the values.

var ent = new Entity("account");
           ent["mytestproperty"] = "Test Name";
           ent["mytestproperty2"] = 1;
           ent["myentityreference"] = new EntityReference("contact", Guid.Empty);

           var ent2 = new Entity("contact");
           ent2["mytestproperty"] = "Test Name";
           ent2["mytestproperty2"] = 1;
           ent2["myentityreference"] = new EntityReference("contact", Guid.Empty);


           context.OutputParameters["CollectionParam"] = collection;

First we have to understand that entitycollection is a collection of entities. It does not necessarily imply collection of entities of the same type. This is a common misconception I find among so many people in spite of working on CRM for quite sometime.

As you can see, both the entities are of different types and can have completely different properties. Cool isn’t it?

And Below is the result the invoker of the action receives.



Personally if you ask me, I would still prefer serializing the object into JSON or XML. However if your customer prefers Entity or EntityCollection, this workaround I hope helps you.


Debajit Dutta

(Dynamics MVP)

For corporate training/ consulting/ tools, please visit our website or write to us at