Wednesday, May 03, 2017

Extracting CRM solution using the solutionPackager tool

Here is how one can use the SolutionPackager to extract the solution file into individual files. (more info:

solutionpackager /action:Extract /zipfile:NCM-SB1\ /folder:NCM-SB1\Solution


1. You can extract the files to make it easier to put them into source control

2. You can extract the files from similar solutions from 2 different organizations and then compare them for differences.

CRM–Default solution fails to export

Whenever I tried to export the default solution from our on-premise 2016 instance, it would error out after about 6 minutes with a generic error of: “Unexpected error occurred

On the webserver running CRM, I found the following error message:

- <Event xmlns="">
- <System>
  <Provider Name="MSCRMWebService" />
  <EventID Qualifiers="49152">18176</EventID>
  <TimeCreated SystemTime="2017-05-03T16:41:46.000000000Z" />
  <Security />
- <EventData>
  <Data>Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35</Data>
  <Data>Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values) at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider) at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context) at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context) Inner Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Crm.Tools.ImportExportPublish.WorkflowHandler.RaiseExceptionIfNotActivatedBPF(WorkflowEntity workflow) at Microsoft.Crm.Tools.ImportExportPublish.WorkflowHandler.ExportItem(XmlDocument XDoc, XmlNode Node) at Microsoft.Crm.Tools.ImportExportPublish.ExportHandler.Export(XmlDocument XDoc) at Microsoft.Crm.Tools.ImportExportPublish.RootExportHandler.RunExport() at Microsoft.Crm.WebServices.ExportXmlService.ExportSolutionWithTargetVersion(String solutionName, Boolean managed, String targetVersion, Boolean exportAutoNumberingSettings, Boolean exportCalendarSettings, Boolean exportCustomizationSettings, Boolean exportEmailTrackingSettings, Boolean exportGeneralSettings, Boolean exportMarketingSettings, Boolean exportOutlookSynchronizationSettings, Boolean exportRelationshipRoles, Boolean exportIsvConfig, Boolean exportSales, Boolean exportExternalApplications, ExecutionContext context)</Data>

The fact that it was happening on “RaiseExceptionIfNotActivatedBPF”, told me it had something to do with workflows.

Looking for ways to fix it on the interwebs brought me to the following post:, which points out the fact that Workflow records somehow got messed up with the upgrade. Simply, running the following statement worked for me:

IMPORTANT: Running sql directly against your CRM database is not supported and could void your warranty. So do so, at your own peril!

Please note: I did this on a test CRM instance that was not going to be used in production. If you plan on using this fix, it is probably better for you to engage Microsoft Support and have them look at your organization database.

UPDATE WorkflowBase
      BusinessProcessType = 0
WHERE Category = 4
      AND BusinessProcessType IS NULL;

But in case that doesn't, run the following script in its entirety:

SELECT name,
FROM workflowbase
WHERE name = 'Opportunity Sales Process';
UPDATE WorkflowBase
      UniqueName = 'opportunitysalesprocess'
WHERE WorkflowId = '3E8EBEE6-A2BC-4451-9C5F-B146B085413A';
SELECT Businessprocesstype,
FROM workflowbase
WHERE category = 4;
SELECT UniqueName,
FROM workflowbase
WHERE WorkflowId = '3E8EBEE6-A2BC-4451-9C5F-B146B085413A';
UPDATE WorkflowBase
      SupportingSolutionId = NULL
WHERE WorkflowId = '3E8EBEE6-A2BC-4451-9C5F-B146B085413A';
UPDATE WorkflowBase
      BusinessProcessType = 0
WHERE Category = 4
      AND BusinessProcessType IS NULL;
UPDATE WorkflowBase
      UniqueName = 'phonetocaseprocess'
WHERE WorkflowId = '0FFBCDE4-61C1-4355-AA89-AA1D7B2B8792';
UPDATE WorkflowBase
      UniqueName = 'leadtoopportunitysalesprocess'
WHERE WorkflowId = '919E14D1-6489-4852-ABD0-A63A6ECAAC5D';


Thursday, April 20, 2017

IE Developer tools crashes on Dynamics CRM

Unhandled exception in Iexplorer.exe


I found that it was related to “Learning Path” and opting out of “learning path” allows developer toolbar to work correctly.

Saturday, April 08, 2017

Dynamics CRM–Status to Status Reason Mapping (statecode to statuscode)

SELECT distinct e.LogicalName as entity,
      smState.Value AS [State/StateCode],
       smstate.AttributeValue as stateCode,
       smStatus.Value AS [statusReason/statusCode],
       smStatus.AttributeValue as statusCode
FROM StatusMap sm
     JOIN Entity e ON sm.ObjectTypeCode = e.ObjectTypeCode
     JOIN StringMap smState ON smState.AttributeValue = sm.State
                               AND smState.ObjectTypeCode = e.ObjectTypeCode
                               AND smState.AttributeName = 'StateCode'
     JOIN StringMap smStatus ON smStatus.AttributeValue = sm.Status
                                AND smStatus.ObjectTypeCode = e.ObjectTypeCode
                                AND smStatus.AttributeName = 'StatusCode'
WHERE  1=1
and e.IsCustomEntity = 0
and e.LogicalName in ('lead','account','contact','opportunity')
ORDER BY e.LogicalName,

Thursday, March 30, 2017

Useful bookmarklets for working with CRM

Here are some useful bookmarkets that I have collected for working with Dyanmics CRM (tested with CRM 2016)

  1. Download the files from: (you need just the folder CrmDev).
  2. Open the following location via Windows Explorer: %userprofile%\Favorites\Links
  3. Copy the folder CrmDev into the folder opened in (2).
  4. You will now have access to the bookmarks in IE.

Alternatively, you can use the following html and use the import functionality in your favorite browser to get these links. (source:

Thursday, February 02, 2017

Headless Authentication against CRM 365 WebApi

Or how to authenticate against the CRM 365 web-api, without a user-name and password.

Background: We had to write a web-service that communicated with CRM. And because it was going to be a web-service that was communicating with CRM web-api, we didnt want to use a user-name and password and instead, we wanted to just use . And hence the name  “headless authentication”.

Create an Azure App Registration:

  1. Login to Azure portal:
  2. Navigate to the “App Registrations” blade, and add an app
    1. Click on “Add”
    2. image
    3. Enter a value for name, set the application type to “Web App/API” and enter a sign-on URL (any value will do). Click Create
    4. Return to the “App Registrations” blade and select the new app you created in step 3.
    5. You should now see the essential settings of the app:
      You will need the Application ID later.
    6. Click on All Settings and then Choose “Required Permissions”. Click on Add
      In “Select an API”, select the “Dynamics CRM Online” API and click Select.
      Next under “Select Permissions”, select “Access CRM Online as organization users” and then click Select.
      Finally, click Done. The result should look like this:
    7. Next, click on “Keys” and add a new row, where you set the Description value to “key” (this can be any value), Expires: Never and then click “Save”.
      The value field will update. Copy the value and save it. Once you leave this view, you will not be able to retrieve this key again. This is the shared secret your application will use to authenticate.

Setup a CRM user for the application

  1. Go to the “Security” options
  2. Choose the “Application Users” view
  3. Click New (make sure the User type is set to “Application User”)
  4. Set the application id to the value you from step 5 of Create an Azure App Registration.
  5. Enter an email and a name for the application user.
  6. Click Save.
  7. Click on “Manage Roles” and assign a role to the user (note: you cannot use a system role and you will need to use a custom role).

Create a console app to test the code

  1. Test the code using the repo:

Sunday, November 13, 2016

Programming the LiftMaster 374UT with the 8550 MyQ garage opener

The instructions are confusing in the 374UT manual, and I spent about 30 minutes trying to program the remote, before I figured out exactly what needs to be done.

Here are the steps:

  1. Start with your garage door closed.
  2. Put the 374UT remote into programming mode
    1. Press the bottom button until the blue LED lights up solid
  3. Press the learning button in the garage door opener
    1. The learn button on the garage door opener should glow solid.
  4. Press the button on the 374UT remote that you wish to program to control the garage door open.
    1. You will see the blue LED on the remote start to flash. (Dont press the button a second time just yet – this is what the manual tells you to do and messes everything up).
    2. Instead you should see the light on the garage door flash and hear 2 clicks
    3. Next, the blue LED on the 374UT remote should stop flashing (may take a few seconds before this happens). When it finishes flashing, press the button you are programming a 2nd time. Again the blue LED will start flashing. Be patient, it takes about another 30 seconds. Once the programming is complete, and the programming setup was successful, the garage door will begin to open.
    4. Press any button on 374UT button quickly. This will complete the programming.

Friday, August 05, 2016

SSMS and storing templates in a different location

In Sql Server Management Studio (SSMS), there doesnt seem to be a way to store the templates in a location other than the default (which is: %appData%\Microsoft\SQL Server Management Studio\12.0\Templates\Sql). I use this feature heavily, but everytime I get a new computer, I end up loosing them templates that I have collected over time.

I found a simple solution around this and it uses the “mklink” command.


1. Open a command prompt and CD to: “%appData%\Microsoft\SQL Server Management Studio\12.0\Templates\Sql”

2. Run the command:

mklink /D MyTemplates C:\OneDrive\SqlTemplates

The above command creates a link from within the folder that SSMS looks for templates to a folder on c drive (I am mapping it to folder thats backed up by one-drive).

3. Restart SSMS, and voila, you should see this folder in your templates explorer.

Saturday, July 16, 2016

Opening JSON directly in IE

You need to add the following entries into the registry after which IE will directly render the JSON data instead of prompting to save the file:

Windows Registry Editor Version 5.00
; Tell IE to open JSON documents in the browser. 
; 25336920-03F9-11cf-8FD0-00AA00686F13 is the CLSID for the "Browse in place" .

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json]

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/json]

Tuesday, June 14, 2016

Fiddler and vshub requests

If you debug a web-site project using Visual Studio 2015 or higher, you may see a ton of requests to the URL /vshub/ in fiddler. These requests are used by Visual Studio and the VsHub process to communicate with each other and are not actually related to your website.

So what can you do?

1. You can setup a filter to filter out the /vshub/ uris.

2. I prefer custom rule that I can turn on or off and here is what it looks like:

Edit the customRules.js file (Rules > Customize Rules).

Add the following lines to class Handler

public static RulesOption("Display VSHUB Requests")
var m_bShowVshubRequests: boolean = false;

In “OnBeforeRequest” add the following code:

static function OnBeforeRequest(oSession: Session) {
        if (!m_bShowVshubRequests && oSession.uriContains("/vshub/"))
            oSession.Ignore(); //oSession["ui-hide"] = "true";

And now by default it will never show and if you want to look at it, you can do so by enabling it at: