CRM Indexing Management & Rebuild Index Scheduled Jobs

Reviewing index fragmentation on the CRM database is an important aspect for monitoring the CRM organizations as high levels of fragmentation will badly impact the performance, the fragmented indexes can be sorted out by reorganizing or rebuilding.

CRM provides 2 scheduled jobs for Indexes management:

  1. Indexing Management: responsible for creating indexes for any quick find columns
  2. Rebuild Index: responsible for maintaining the indexes fragmentation by doing index rebuild

Although it is supported by Microsoft to manually create or rebuild indexes but it is a best practice to let the scheduled jobs mentioned above do these 2 functions, if you needed to create a new index for a searchable column just add it to the quick find view and the next time the index management job runs it will automatically create the index for you.


Limitations to using Business Rules – CRM 2015

Here are the main limitations to using business rules from Microsoft official materials:

  • Business rules run only when the form loads and when field values change. They do not run when a record is saved, unless the scope for the rule is set at an entity level.
  • Business rules work only with fields. If you need to interact with other visible elements, such as tabs and sections, within the form you need use form scripts.
  • When you set a field value by using a business rule, any OnChange event handlers for that field will not run. This is to reduce the potential for a circular reference, which could lead to an infinite loop.
  • If a business rule references a field that is not present on a form, the rule will simply not run. There will be no error message.
  • Whole Number fields that use the formats for TimeZone, Duration, or Language will not appear in the rule editor for the conditions or actions, so they cannot be used with business rules.
  • For Microsoft Dynamics CRM for tablets, the definition of the business rules are downloaded and cached when CRM for tablets opens. Changes made to business rules are not applied until CRM for tablets is closed and re-opened.
  • When you set the value of a lookup field, the text of the primary field value that is set in the form will always match the text that is visible in the rule definition. If the text representing the primary field value of the record you are setting in the lookup changes, the value set by your rule will continue to use the text portion of the primary field value defined by the rule. To fix this, update the rule definition to use the current primary name field value.

I want to add that you can’t debug business rules as you can do when witting JavaScript code.

Moving Site Collection to Different Web Application – SharePoint

We created a site collection for saving CRM documents on Intranet web application, we wanted to move that site collection to a new web application to avoid having a single point of failure for the 2 site collections and also allow the CRM administrators to control the maximum attachment size for files stored on SharePoint.

We achieved this by running the below 2 PowerShell cmdlets:

Backup-SPSite -Identity “” -Path “C:\CRMDocumentsSiteCollection.bak”

Restore-SPSite -Identity “” -Path “C:\CRMDocumentsSiteCollection.bak”

The site collection will be created if not already existing, and if we want to override an already existing site collection on the specified URL then we will need to add the -force parameter.

Then we re-configured the documents management settings in CRM to point to the new site collection URL, the good thing about CRM is that it saves the document locations relatively, so such a change in the base URL only requires updating the SharePoint site URL and everything works fine.

Please note that in case you faced a SQL timeout while re-configuring the document management settings in CRM due to having large number of documents then you will need to increase the CRM SQL timeouts on the front end servers.

CRM 2015 SLA New Features – Differences

CRM 2015 SLA is now having 2 main types:

  • Standard SLA
  • Enahanced SLA

Below is a comparison between the 2 types:

Standard SLA Enhanced SLA
Populates First Response by and/or Resolve by values in the case entity. Uses a new entity (SLA KPI Instance) to store this data.
Failure time stamped on case entity attributes. Failure/Warning times stamped on related SLA KPI Instance record displayed via a sub grid in the case form
Timer control based on case entity fields; can be directly added to case form. Timer control based on related SLA KPI Instance fields; can be added using Quick From
SLA Pause/Resume is not available SLA Pause/Resume while SLA Time calculation is automatically paused when a case is put on Hold, also the amount of time on hold is also tracked.

There is system setting that allows pausing cases SLA automatically for certain case status reasons.

The ability to pause can be disabled/enabled for each SLA.

Success actions are not available. Trigger actions when an SLA is successful

Important Considerations:

  • Cannot change SLA type once created.
  • Case SLA cannot be sorted by Enhanced SLA fields as they are now on another entity.
  • Queue Item views cannot display Enhanced SLA fields.

CRM & SQL Server BizTalk Integration

We had a project in which there was a requirement for an integration between Microsoft SQL server and Microsoft Dynamics CRM 2011 using BizTalk 2013 R2, the solution in brief was Listening on SQL server using the WCF-Custom Adapter then using the orchestration to do data mapping then send the new transformed message to a custom WCF service that handles inserting the message as a new case in CRM, below are the hard learned lessons for such integration:

  • When receiving message from SQL server with a specific schema, make sure the SQL statement is returning xml results matching the same schema defined in the orchestration or the mapping process will not be able of transforming the message to the target schema.
  • When constructing a message using message assignment in an orchestration, check the message in the constructed messages property in the construct shape to resolve the build time error in case trying to assign value to a message not constructed from a receive shape.
  • When configuring the WCF-Custom SQL binding connection, if there is only one default instance on the SQL server then you need to use the below format with double slash between the server name and the database name for the URI connection string: mssql://ServerName//DatabaseName
  • When using the WCf-Custom adapter, there is an important property named UseAmbientTransaction which is defaulted to true, this property specifies whether the adapter will use DTC transactions in the communication with SQL server or use normal queries that doesn’t require DTC, you need to make sure that DTC is enabled on SQL server and is working properly by using a tool named DTCPing, sometimes the adapter will not work properly while not throwing any errors on the BizTalk server due to DTC issues like DNS name resolution that is blocking the transaction only on the SQL server side.

The experience with this integration was fruitful, interesting, and leveraged how BizTalk can be used to build robust and powerful integration solutions.

WCF and ASP.NET Web API, When to use what?

I found myself confused between WCF services and the new ASP.NET Web API, I researched about the differences and resulted to the following:

The following table describes the major features of each technology.

Enables building services that support multiple transport protocols (HTTP, TCP, UDP, and custom transports) and allows switching between them. HTTP only. First-class programming model for HTTP. More suitable for access from various browsers, mobile devices etc enabling wide reach.
Enables building services that support multiple encodings (Text, MTOM, and Binary) of the same message type and allows switching between them. Enables building Web APIs that support wide variety of media types including XML, JSON etc.
Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security. Uses basic protocol and formats such as HTTP, WebSockets, SSL, JQuery, JSON, and XML. There is no support for higher level protocols such as Reliable Messaging or Transactions.
Supports Request-Reply, One Way, and Duplex message exchange patterns. HTTP is request/response but additional patterns can be supported through SignalRand WebSockets integration.
WCF SOAP services can be described in WSDL allowing automated tools to generate client proxies even for services with complex schemas. There is a variety of ways to describe a Web API ranging from auto-generated HTML help page describing snippets to structured metadata for OData integrated APIs.
Ships with the .NET framework. Ships with .NET framework but is open-source and is also available out-of-band as independent download.

Use WCF to create reliable, secure web services that accessible over a variety of transports. Use ASP.NET Web API to create HTTP-based services that are accessible from a wide variety of clients. Use ASP.NET Web API if you are creating and designing new REST-style services. Although WCF provides some support for writing REST-style services, the support for REST in ASP.NET Web API is more complete and all future REST feature improvements will be made in ASP.NET Web API. If you have an existing WCF service and you want to expose additional REST endpoints, use WCF and the WebHttpBinding.


  1. Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
  2. Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
  3. Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
  4. Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.
  5. Choose Web API when you don’t have a requirement to support SOAP.


Install CRM 2013 Developer Toolkit on Visual Studio 2013

I had a hard time to install the CRM developer toolkit found in CRM 2013 SDK on VS 2013 that is running on Windows Server 2012 R2, so I thought of sharing the steps to make this happen:

  1. Download the CRM 2013 SDK and after extracting it navigate to: sdk\Tools\DeveloperToolkit\
  2. Open a Command Prompt as Administrator
  3. Run: msiexec /a CrmDeveloperToolsVS12_Installer.msi /qb TARGETDIR=c:\temp
  4. Navigate to the folder which you extracted the files
  5. Open the Visual Studio folder
  6. Open the archive file Microsoft.CrmDeveloperTools.vsix (I used 7-Zip for this)
  7. Edit extension.vsixmanifest
  8. Replace: InstalledByMsi=”true” with: InstalledByMsi=”false”
  9. Replace all instances of: Version=”[11.0,12.0)” with: Version=”[11.0,12.0]“ (note the closing bracket changed) and update the file in the archive.
  10. Double click to install the VSIX package Microsoft.CrmDeveloperTools.vsix found in the visual studio folder.
  11. Add the files found in the folder named “CRM MSBuild” extracted from the CrmDeveloperToolsVS12_Installer.msi to the folder in the path “C:\Program Files (x86)\MSBuild\Microsoft\CRM”
  12. If things didn’t work out you may need to edit C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe.config and add the following lines:
    <assemblyIdentity name=”Microsoft.Windows.Design.Host” publicKeyToken=”b03f5f7f11d50a3a” culture=”neutral” />
    <bindingRedirect oldVersion=”″ newVersion=”″ />

In case the CRM explorer window is not loading when opening the CRM Toolkit project types you will need to add the below lines in the visual studio solution file:

  GlobalSection(CRMSolutionProperties) = preSolution
    SolutionIsBoundToCRM = TRUE