Migrate inventory dimensions add via customization/overlayering to inventory dimensions through extension in MsDyn365FO

If you want to migrate an inventory dimension add via customization/overlayering to inventory dimensions through extension in Microsoft Dynamics 365 for Finance and Operation, you can find some hint in this post, which are currently not included in the documentation provided by Microsoft.

As written in my previous post, we recently upgrading one of our Microsoft Dynamics 365 for Finance and Operation customers from version 7.1 PU18 to version 8.1.2 PU22. Within this upgrade we also upgraded an inventory dimension add via customization/overlayering to an inventory dimension add via extension.

The documentation in this area is quite good, but missing one major piece: data upgrade 

If you migrate to version 8.1.X or 10 the class WHSInventReservePopulateParentInventDimId gets executed during data upgrade. The problem with this code is, that prior to this process you have to migrate the data of your old inventory dimension to the new InventDimension1 – InventDimension10. If you missed this step you have corrupted data in table WHSInventReserve and in case of large amount of data you will hit the space limit of your tempdb because of an cartesian product. In our case we ran into this problem on a developer machine during one of the rounds of testing the data upgrade. It took us quite some time to find the root cause, so I want to save you some time.

To get the data of the old inventory dimension migrate to the new InventDimension1 – InventDimension10 prior to WHSInventReservePopulateParentInventDimId gets executed you have to do the following things:

  1. Move the field of your old inventory dimension on table InventDim to a table extension, to do not lose the data and migrate the data during data upgrade.
  2. Add the following code extension to a package where you can access the field of your old inventory dimension and the implementation of your new inventory dimension add via extension. This code extension will migrate the data before the next() call will execute the logic from class WHSInventReservePopulateParentInventDimId.

 [ExtensionOf(classStr(WHSInventReservePopulateParentInventDimId))]

final class WHSInventReservePopulateParentInventDimIdUPD_Extension

{

   public static void populateForAllItems()

   {

       // enable ConfigurationKey InventDimension1 befor the execution of populateForAllItems()

       ConfigurationKeySet keySet = new ConfigurationKeySet(); 

       keySet.loadSystemSetup();

       keySet.enabled(configurationKeyNum(InventDimension1), true); 

       SysDictConfigurationKey::save(keySet.pack());

       SysSecurity::reload(true, true, true, false); 

       // TODO: Add EcoResTrackingDimensionGroupFldSetup for MyNewInventoryDimension to each EcoResTrackingDimensionGroup and set IsActive accordingly 

       // TODO: Add WHSReservationHierarchyElement for MyNewInventoryDimension to each WHSReservationHierarchy and set ReservationHierarchyLevel accordingly 

       // transfer MyOldInventoryDimension to InventDimension1 in table InventDim

       InventDim inventDim;

       while select forupdate inventDim

           where inventDim.MyOldInventoryDimension != ”

       {

           ttsbegin; 

           inventDim.parmMyNewInventoryDimension(inventDim.MyOldInventoryDimension);

           inventDim.MyOldInventoryDimension = ”;

           inventDim.update(true); 

           ttscommit;

       }

       // transfer MyOldInventoryDimension to InventDimension1 in table InterCompanyInventDim

       InterCompanyInventDim interCompanyInventDim;

       while select forupdate interCompanyInventDim

           where interCompanyInventDim.MyOldInventoryDimension != ”

       {

           ttsbegin; 

           interCompanyInventDim.parmMyNewInventoryDimension(interCompanyInventDim.MyOldInventoryDimension);

           interCompanyInventDim.MyOldInventoryDimension = ”;

           interCompanyInventDim.update(); 

           ttscommit;

       }

       // transfer MyOldInventoryDimension to InventDimension1 in table InventDimParm

       InventDimParm inventDimParm;

       while select forupdate inventDimParm

           where inventDimParm.MyOldInventoryDimensionFlag == NoYes::Yes

       {

           ttsbegin; 

           inventDimParm.parmMyNewInventoryDimensionFlag(inventDimParm.MyOldInventoryDimensionFlag);

           inventDimParm.MyOldInventoryDimensionFlag = NoYes::No;

           inventDimParm.update(); 

           ttscommit;

       } 

       next populateForAllItems();

   } 

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s