Party relationship types Database Sync Issue
If you have a requirement to extend the DirSystemRelationshipType enum. So be ready to get the DB synchronization issue on your Azure UAT and DEV-TEST environment.
You will get the below error on the run-book If you don't perform the pre-requisite step before deploying the package.
Application configuration sync failed. Microsoft.Dynamics. AX.Framework.Database.TableSyncException: Custom action sync failed with error: 'NullReferenceException: Object reference not set to an instance of an object.
at Dynamics.AX.Application.DirRelationshipTypeTable.initFromSystemRelationshipType(DirSystemRelationshipType _systemType) in xppSource://Source/Directory\AxTable_DirRelationshipTypeTable.xpp:line 8
at Dynamics.AX.Application.DirDataPopulation.insertDirRelationshipTypes() in xppSource://Source/Directory\AxClass_DirDataPopulation.xpp:line 265
at Dynamics.AX.Application.DirDataPopulation.populateDirData() in xppSource://Source/Directory\AxClass_DirDataPopulation.xpp:line 628
at Dynamics.AX.Application.DirSetup.loadData() in xppSource://Source/Directory\AxClass_DirSetup.xpp:line 34
at Dynamics.AX.Application.DirSetup.numberSequenceModuleSetupLoadDataHandler() in xppSource://Source/Directory\AxClass_DirSetup.xpp:line 45
at Dynamics.AX.Application.NumberSequenceModuleSetup.loadData() in xppSource://Source/ApplicationFoundation\AxClass_NumberSequenceModuleSetup.xpp:line 21
at Microsoft.Dynamics.AX.Deployment.Setup.AppOperations.NumberSequenceSetup()
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.<>c__DisplayClass28_0.<RunCustomAction>b__0()
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.ExecuteWithinAOS(SyncOptions syncOptions, String sqlConnectionString, IMetadataProvider metadataProvider, Func`1 func, Action`1 errorHandler)' ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamics.AX.Application.DirRelationshipTypeTable.initFromSystemRelationshipType(DirSystemRelationshipType _systemType) in xppSource://Source/Directory\AxTable_DirRelationshipTypeTable.xpp:line 8
at Dynamics.AX.Application.DirDataPopulation.insertDirRelationshipTypes() in xppSource://Source/Directory\AxClass_DirDataPopulation.xpp:line 265
at Dynamics.AX.Application.DirDataPopulation.populateDirData() in xppSource://Source/Directory\AxClass_DirDataPopulation.xpp:line 628
at Dynamics.AX.Application.DirSetup.loadData() in xppSource://Source/Directory\AxClass_DirSetup.xpp:line 34
at Dynamics.AX.Application.DirSetup.numberSequenceModuleSetupLoadDataHandler() in xppSource://Source/Directory\AxClass_DirSetup.xpp:line 45
at Dynamics.AX.Application.NumberSequenceModuleSetup.loadData() in xppSource://Source/ApplicationFoundation\AxClass_NumberSequenceModuleSetup.xpp:line 21
at Microsoft.Dynamics.AX.Deployment.Setup.AppOperations.NumberSequenceSetup()
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.<>c__DisplayClass28_0.<RunCustomAction>b__0()
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.ExecuteWithinAOS(SyncOptions syncOptions, String sqlConnectionString, IMetadataProvider metadataProvider, Func`1 func, Action`1 errorHandler)
--- End of inner exception stack trace ---
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.<>c.<RunCustomAction>b__28_1(Tuple`2 result)
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.ExecuteWithinAOS(SyncOptions syncOptions, String sqlConnectionString, IMetadataProvider metadataProvider, Func`1 func, Action`1 errorHandler)
at Microsoft.Dynamics.AX.Framework.Database.Tools.LegacyCodepath.RunCustomAction(SyncOptions syncOptions, String sqlConnectionString, IMetadataProvider metadataProvider, Action`1 a)
at Microsoft.Dynamics.AX.Framework.Database.Tools.SyncEngine.PostTableSync()
at Microsoft.Dynamics.AX.Framework.Database.Tools.SyncEngine.FullSync()
at Microsoft.Dynamics.AX.Framework.Database.Tools.SyncEngine.RunSync(SyncOptions options)
at Microsoft.Dynamics.AX.Framework.Database.Tools.SyncEngine.Run(String metadataDirectory, String sqlConnectionString, SyncOptions options)
11/28/2017 18:37:51: The operation failed.
This step works manually in VS and fails during the deployment is because during the deployment the system will run some extra steps different than the simple DBSync in VS. For instance, the system is here trying to set up the Number Sequences and it is kind of failing in the Dynamics.AX.Application.DirRelationshipTypeTable.initFromSystemRelationshipType(DirSystemRelationshipType _systemType) in xppSource://Source/Directory\AxTable_DirRelationshipTypeTable.xpp:line 8
So, it could be that you are missing any reference here, or your package does not include any reference model. If you create a runnable class in your development box and run NumberSequenceModuleSetup.loadData()
Resolution
First, search the DirSystemRelationshipType in AOT and identify the extended elements.In my case, We only added one element Named > Friend. You can the below screenshot.
There is two way to fix the issue.
- 1st-way
Go to organization Administration > Organization > Relationship type
Now add the elements you added in the extended enum and you identified in our above steps. In my case, we Added only One element Friend So create a new record in the relationship type list page. please check the screenshot.
End of the first way to fix the issue. for the verification, you can sync the DB using a power shell.
In the below, I have explained how to fully sync a database using a power shell.
2nd-way
First, find the class in AOT DirRelationshipTypeChildInitialize and copy-paste the complete content in the new class like the below screenshot and replace the highlighted elements.
- 1st highlighted section I replaced from Child to Friend
- 2nd highlighted section I replaced from DirPartyType::Person to DirPartyType::None
- 3rd highlighted section I replaced with my label.
After all of the above steps build the model and for testing purposes of populating the new relationship type, you can create a runnable class, and call DirDataPopulation::insertDirRelationshipTypes() in Main(). You should see the new relationship type in the DirRelationshipTypeTable, and the new relationship type will be available on the Relationship types page.
You can also verify by executing the DB Sync with Power Shall
In the below, I have explained how to fully sync the database using the power shell.
I have executed the same and the result was found as expected. check the below screenshots.