I came across a strange issue within Dynamics 365 that I’d never seen before this week. A customer had made updates to the Status Reason (statuscode) field on the Order entity and after the change was saved and published we could no longer open the field properties for the field from the customization area. Trying to open the Status Reason gave the following error:
Error
An error has occurred.
Try this action again. If the problem continues, check the Microsoft Dynamics 365 Community for solutions or contact your organization’s Microsoft Dynamics 365 Administrator. Finally, you can contact Microsoft Support.
It seems that after the change was published, the Status Reason field was corrupted. To make matters worse the Order form would no longer open either. Downloading the log file from the form error gave the following information:
Unhandled Exception: System.ServiceModel.FaultException1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.at Microsoft.Crm.Application.InlineEdit.JsonWrapperFactory.CreateForStatusAttribute(StatusAttributeMetadata attributeMetadata, String entityLogicalName)at Microsoft.Crm.Application.InlineEdit.JsonWrapperFactory.Create(AttributeMetadata attributeMetadata, String entityLogicalName)
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Crm.Application.InlineEdit.JsonWrapperFactory.CreateForStatusAttribute(StatusAttributeMetadata attributeMetadata, String entityLogicalName) at Microsoft.Crm.Application.InlineEdit.JsonWrapperFactory.Create(AttributeMetadata attributeMetadata, String entityLogicalName) at Microsoft.Crm.Application.InlineEdit.JsonWrapperFactory.CreateEntityWrapper(Int32 entityTypeCode, String formId, ICollection
1 attributesOnForm, ICollection`1 unboundControlsOnForm)at Microsoft.Crm.Application.InlineEdit.ReadFormDataBuilder.RetrieveFormattedEntityMetadata() at Microsoft.Crm.Application.Pages.Common.ReadLayoutPage.WriteEntityMetadata(TextWriter writer) at Microsoft.Crm.Application.Pages.Common.ReadLayoutPage.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously): Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #F865F716</Message>
The following information from the error stood out to me and confirmed that it was something to do with the status:
CreateForStatusAttribute(StatusAttributeMetadata attributeMetadata, String entityLogicalName)
How to fix it
Since there was no chance of opening the Status Reason field from the customization area to fix it, the only option was to export the metadata and fix things via XML.
Examining the XML everything seemed Ok and the defaults for each status where legit values within the status reason and I could spot nothing wrong with the status reason options.
To fix it I exported the same fields from an unmodified version for Dynamics 365 and replaced the <optionset> attributes for both the Status and Status Reason fields in my file.
The steps below outline the process I took to resolved it:
- Add the Status and Status reason fields for the problematic entity into a Solution and export it.
- Unzip the file and open Customizations.xml within a text / XML editor
- Do the same process from an unmodified Dynamics 365 system. Note: I signed up for a trial version and did it from there.
- Replace the <optionset> attribute for the salesorder_statecode field with the values from the unmodified system
- Replace the <optionset> attribute for the salesorder_statuscode field with the values from the unmodified system
- Zip the modified customizations.xml and all other associated files
- Import and publish the new zip file
Once the changes have been published, refresh your browser cache and retry opening the form and the Status Reason field. Once confirmed everything is working again, retry the customizations.
FYI: Here are the values I used to replace the <optionset> attributes on the Order (salesorder) entity
salesorder_statecode:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<optionset Name="salesorder_statecode"> <OptionSetType>state</OptionSetType> <IntroducedVersion>5.0.0.0</IntroducedVersion> <displaynames> <displayname description="Status" languagecode="1033" /> </displaynames> <Descriptions> <Description description="Status of the order." languagecode="1033" /> </Descriptions> <states> <state value="0" defaultstatus="1" invariantname="Active"> <labels> <label description="Active" languagecode="1033" /> </labels> </state> <state value="1" defaultstatus="3" invariantname="Submitted"> <labels> <label description="Submitted" languagecode="1033" /> </labels> </state> <state value="2" defaultstatus="4" invariantname="Canceled"> <labels> <label description="Canceled" languagecode="1033" /> </labels> </state> <state value="3" defaultstatus="100001" invariantname="Fulfilled"> <labels> <label description="Fulfilled" languagecode="1033" /> </labels> </state> <state value="4" defaultstatus="100003" invariantname="Invoiced"> <labels> <label description="Invoiced" languagecode="1033" /> </labels> </state> </states> </optionset> |
salesorder_statuscode:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<optionset Name="salesorder_statuscode"> <OptionSetType>status</OptionSetType> <IntroducedVersion>5.0.0.0</IntroducedVersion> <displaynames> <displayname description="Status Reason" languagecode="1033" /> </displaynames> <Descriptions> <Description description="Reason for the status of the order." languagecode="1033" /> </Descriptions> <statuses> <status value="1" state="0" TransitionData="" Color="#0000ff"> <labels> <label description="New" languagecode="1033" /> </labels> </status> <status value="2" state="0" TransitionData="" Color="#0000ff"> <labels> <label description="Processing" languagecode="1033" /> </labels> </status> <status value="3" state="1" TransitionData="" Color="#0000ff"> <labels> <label description="In Progress" languagecode="1033" /> </labels> </status> <status value="4" state="2" TransitionData="" Color="#0000ff"> <labels> <label description="No Money" languagecode="1033" /> </labels> </status> <status value="100001" state="3" TransitionData="" Color="#0000ff"> <labels> <label description="Complete" languagecode="1033" /> </labels> </status> <status value="100002" state="3" TransitionData="" Color="#0000ff"> <labels> <label description="Partial" languagecode="1033" /> </labels> </status> <status value="100003" state="4" TransitionData="" Color="#0000ff"> <labels> <label description="Invoiced" languagecode="1033" /> </labels> </status> </statuses> </optionset> |
Good luck and feel free to comment if you have any issues.