Wednesday, May 03, 2017

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="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="MSCRMWebService" />
  <EventID Qualifiers="49152">18176</EventID>
  <Level>2</Level>
  <Task>0</Task>
  <Keywords>0x80000000000000</Keywords>
  <TimeCreated SystemTime="2017-05-03T16:41:46.000000000Z" />
  <EventRecordID>168537</EventRecordID>
  <Channel>Application</Channel>
  <Computer>xxxxxxxxxxxx</Computer>
  <Security />
  </System>
- <EventData>
  <Data>xxxxxxx</Data>
  <Data>xxxxxxxx</Data>
  <Data>none</Data>
  <Data>30</Data>
  <Data>ExportSolution</Data>
  <Data>Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</Data>
  <Data>Microsoft.Crm.Extensibility.InternalOperationPlugin</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>
  </EventData>
  </Event>

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:https://community.dynamics.com/crm/f/117/t/232669, 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
  SET
      BusinessProcessType = 0
WHERE Category = 4
      AND BusinessProcessType IS NULL;

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

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

COMMIT TRAN;

No comments: