Register a Dynamics 365 app with Azure Active Directory

  • Sign in to Microsoft Azure Management Portal or Sign up for a free trial. The account should be in the same Office 365 tenant where we would like to register the app. (or link existing Azure Subscription not in same tenant as CRM)

  • Inside Azure Management Portal select Azure Active Directory

  • Select App registrations and click Add

  • Provide required details for the App and click Create

  • Select the App created to get the required details

  • To give permission to App to access Dynamics CRM, click on Required Permissions in API Access section

  • Click on Add

  • Select Dynamics CRM Online

We’d get the notifications.

  • Along with Client id we would also need Authorization Endpoint, when we develop App.

Hope it helps..


Crm Internal Exception: Singleton Retrieve Query should not return more than 1 record. Query: System.Data.SqlClient.SqlCommand while Importing Solution in Dynamics 365 \CRM 2016 or earlier.


While using “Apply Solution Upgrade” or Import in our Test Instance having managed solution, we got the below error.

The Managed solution had the report set as Viewable By = Organization (we cannot have Individual report in Solution) when it was deployed first. And later the user had set the report to be as Individual manually.

Changing the report back to Organization in TEST and importing the solution again fixed the issue.

Hope it helps..

Using Update to change the status and update owner (instead of SetState and Assign Request) in CRM 2015/2016

Prior to CRM 2015 Update 1, if we had to change the owner or set the state of the record we had to use Assign and SetState Request.

Now we can use our Update request for the same.

For e.g. we have below Active record owned by user named Nishant Rana.

Using below Update Request we can change the owner as well as set the record as inactive in a single request.

Entity demoEntity = new Entity("new_demoentity");

// here we are using alternate key to update the record instead of Guid
demoEntity.KeyAttributes.Add("new_alternatekeyfield", "My Alternate Key 2");

demoEntity.Attributes["new_name"] = "Updated record at " + DateTime.Now.ToShortTimeString();

// update owner id
demoEntity.Attributes["ownerid"] = new EntityReference("systemuser", new Guid("16406B31-5E97-E611-80E3-FC15B42877A8"));

// set record as inactive
demoEntity.Attributes["statecode"] = new OptionSetValue(1);



Point to remember is that if we have plugin registered either PRE or POST on Update and Assign both will be triggered.

Hope it helps..

Sample Code to use UpsertRequest in CRM 2015\2016

UpsertRequest was a new request introduced in CRM 2015 Online Update 1.

The request based on the alternate key specified, looks for the record, if the record is existing it updates it else it creates a new record.

UpsertResponse has a property named RecordCreated which is false if the record is found and updated else it is true if record is created. The Target property holds the reference of the record created or updated.

Suppose we have following record created. It has Alternate key defined on “Alternate Key Field”

Sample Code

As we have demo entity record with alternate key field having value as “My Alternate Key 1” it will update the record.

Running it again this time changing the value for the alternate key field.

It creates a new record.

Hope it helps..

Using PluginTypeStatistic records to monitor plugins \ custom workflow activities hosted in sandbox in CRM 2016 (and earlier)

CRM collects runtime information about the plugins and custom workflow activities executing in sandbox mode in PluginTypeStatistic records every hour or so.

Go to Advanced Find View and select – Plug-in Type Statistics

It gives us details regarding “The average execution time”, “Execution Count”, “Failure Count” etc. for each of the plugins and custom workflow activities.

Hope it helps.

Alternate Keys in CRM 2015\CRM 2016

Let us look at a simple example to understand.

  • Suppose we have a custom entity name Demo Entity.
  • Create a new single line of text field named Alternate Key Field.
  • Create a new Alternate Key Field and specify the above field for it.

  • Click on “Create index for My Alternate Keys for entity Demo Entity” which will create an Index in CRM’s Database.
  • Let us update the following record using Alternate Key

  • Sample code

  • Updated record

  • Currently alternate key can only be defined on field type – string, integer and decimal.
  • The alternate key can be used for Entity Reference as well, wherein instead of specifying GUID we can now use alternate key.

Hope it helps..

Plug-in and Custom Workflow activity tracing in CRM 2015\CRM 2016.

To configure it,

Go to Settings – Administration – System Settings

Here we have selected “All” for enable tracing and registered a sample plugin which only writes trace.

Now perform the event that will trigger the plugin.

Go to Settings – Plugin Trace Logs

Open the Trace Log record

Trace message

In case of enable logging set as Off no trace log records will be created and in case of Exception only when exception occurs trace log record is created.

“Trace logs older than 24 hours are deleted by Bulk Deletion background job”

Hope it helps..

Using RetrieveEntityChangeRequest to track changes in CRM 2015 / 2016.

As a first step,

Enable Change Tracking for the entity, custom Demo Entity in our case here.

Suppose we have 5 records created for Demo Entity.

As we are calling it for the first time DataVersion is set as empty.

We got all the 5 records as new or updated item.

Save the DataToken to be used while determining the changes and to be passed next time.

Now let us delete Record 1 and Record 2 and update Record 5 and run the code again this time passing the DataToken saved

As expected we get 3 changes.

Now suppose we create a new record name Record 6 and still use the old Data Token

As expected we got 4 changes here, which includes the new record 6 as new or update.

Point to remember here is if no version is passed the system will return all the records as new, and system will consider records that are within 90 days, if it is older than 90 days all the records will be returned.

If we have a new record created and deleted before we retrieved for the changes and the record didn’t exist at the time of retrieval, we will still get the record as deleted.

Sample Code

EntityCollection newOrUpdatedEntityCollection = new EntityCollection();
EntityReferenceCollection removeOrDeletedEntityRefCollection = new EntityReferenceCollection();

RetrieveEntityChangesRequest retrieveEntityChangeRequest = new RetrieveEntityChangesRequest();
retrieveEntityChangeRequest.Columns = new ColumnSet();

// pass DataVersion
retrieveEntityChangeRequest.DataVersion = "1018501!10/24/2016 12:31:46";

retrieveEntityChangeRequest.EntityName = "new_demoentity";
retrieveEntityChangeRequest.PageInfo = new PagingInfo();

RetrieveEntityChangesResponse retrieveEntityChangesResponse = (RetrieveEntityChangesResponse)organizationProxy.Execute(retrieveEntityChangeRequest);

foreach (var entity in retrieveEntityChangesResponse.EntityChanges.Changes)
var dataToken = retrieveEntityChangesResponse.EntityChanges.DataToken;

if (entity.Type == ChangeType.NewOrUpdated)
else if (entity.Type == ChangeType.RemoveOrDeleted)

Hope it helps ..

“​SharePoint Attachment Extractor & Metadata Manager” tool for Microsoft Dynamics CRM

Two of the most common requirements of the users while using OOB CRM and SharePoint integration have been

  • To associate some sort of metadata with the  document being uploaded from CRM
  • Moving attachments from notes of a particular record to the corresponding folder in SharePoint.

Finally we have a tool than enhances the Out the box integration between CRM and SharePoint and provides these features (in a fully supported manner)

Get all the details here :

The tool has been developed by one of my closest friends and now also a MVP for Microsoft Dynamics CRM – Debajit Dutta.

Configuring Company News Timeline in CRM 2016 Update 1

It is new feature introduced in CRM 2016 Update 1 for CRM Phone and Tablets that delivers news from Bing about the customers and categorize them.

Go to CRM Admin Center à Solutions to install the solution.

Once installed, open your mobile or tablet CRM App and open any of the existing Lead, Contact, Account or Opportunity record.

We could see all the news in Activity News.

In CRM App for Windows Phone à

Different categories available

Hope it helps.