Implementing InventTrans Refactoring For Microsoft Dynamics AX Applications AX2012
Implementing InventTrans Refactoring For Microsoft Dynamics AX Applications AX2012
Implementing InventTrans
Refactoring for Microsoft
Dynamics AX 2012
Applications
White Paper
This document discusses the refactoring of the InventTrans
table and common design patterns. It also discusses how to
implement these changes when developing new features or
updating existing features.
Date: January, 2011
Author: Kim Moerup, Senior Developer, Inventory Management
Send suggestions and comments about this document to
[email protected]. Please include the title with your
feedback.
Table of Contents
Overview..................................................................................................... 3
Audience ..................................................................................................... 3
Document purpose ...................................................................................... 3
Data model changes .................................................................................... 4
Fields deleted from the InventTrans table ................................................................................ 5
Developing new features ........................................................................................................ 6
Upgrading existing features .................................................................................................... 6
Design patterns........................................................................................... 6
Relationships between inventory transaction originating tables and the InventTrans table .............. 6
Modifying custom code ....................................................................................................... 7
The Direction field ................................................................................................................. 7
The TransType and TransRefId fields ....................................................................................... 7
The ItemRouteId and ItemBomId fields ................................................................................... 7
Conclusion .................................................................................................. 8
2
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
Overview
One of the largest tables in Microsoft Dynamics AX has always been the InventTrans table. Over
time, this table has kept growing because of too much redundant data. Microsoft Dynamics AX 2012
begins to change this trend by starting the process of refactoring parts of the table.
The refactoring has the following purposes:
To refactor parts of the table to avoid redundant data and the inherent risk of inconsistent
data
In previous versions of Microsoft Dynamics AX, fields named InventTransId were used to identify sets
of inventory transactions in the InventTrans table and to identify the origin of inventory transactions in
originating tables, such as the SalesLine, PurchLine, ProdTable, or InventJournalTrans table. Despite
its name, InventTransId was not the ID for inventory transactions. The best way to describe the field
is that it identified the set of inventory transactions related to a given inventory transaction originating
record.
In Microsoft Dynamics AX 2012, we introduce a new table named InventTransOrigin for which RecId is
the primary key, but for which InventTransId is the alternate or natural key. The new table stores
data that is common to all the transactions related to the same inventory transaction originating
record.
Audience
This document is intended for developers building new applications for Microsoft Dynamics AX 2012,
as well as for developers updating their existing application code and data.
Document purpose
This document highlights the new design pattern used to implement relationships between the
InventTrans table and inventory transaction originating tables. When detailing the new pattern, this
document also describes the existing pattern that is being replaced and how developers should
approach refactoring their existing code.
3
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
InventTrans (Ax2009)
<OriginatingTable> (Ax2009)
RecId
RecId
DataAreaId (FK)
InventTransId
ItemId
InventDimId
Qty
TransType
TransRefId (O)
StatusReceipt
StatusIssue
InventTransIdTransfer (O)
Direction (O)
InventTransIdFather (O)
ItemRouteId (O)
ItemBomId (O)
InventTransIdReturn (O)
CustVendAC (O)
AssetId (O)
AssetBookId (O)
InventRefTransId (O)
ProbabilityId (O)
ManyMoreFields
Tables like:
SalesLine
PurchLine
ProdTable
InventJournalTrans
many more
DataAreaId (FK,AK1)
InventTransId (AK1)
ItemId
Qty
InventDimId
AssetInventTrans (Ax2009)
DataAreaId (FK,FK,FK)
AssetId (FK,FK)
InventTransId (FK)
AssetBook
DataAreaId (FK)
AssetBookId
AssetId
BookId (FK)
RecId (AK1)
InventTrans (Ax2012)
InventTransOrigin (Ax2012)
RecId
RecId
DataAreaId (FK)
InventTransOrigin (FK)
ItemId
InventDimId
Qty
StatusReceipt
StatusIssue
ReturnInventTransOrigin (O) (FK)
MarkingRefInventTransOrigin (O) (FK)
ManyMoreFields
DataAreaId (FK,AK1)
InventTransId (AK1)
ReferenceCategory
ReferenceId (O)
ItemId
ItemInventDimId
Party (O) (FK)
Tables like:
SalesLine
PurchLine
ProdTable
InventJournalTrans
many more
Tables like:
InventTransOriginSalesLine
InventTransOriginPurchLine
InventTransOriginProdTable
InventTransOriginJournalTrans
many more
<OriginatingTable> (Ax2012)
InventTransOrigin<OriginatingTable> (Ax2012)
RecId
RecId
DataAreaId (FK)
InventTransId
ItemId
Qty
InventDimId
InventTransOrigin (FK,AK1)
OriginatingTable (FK,AK2)
AssetInventTrans (Ax2012)
DataAreaId (FK,FK)
AssetId (FK)
InventTransOrigin (FK)
AssetBook
DataAreaId (FK)
AssetBookId
AssetId
BookId (FK)
RecId (AK1)
InventTransOriginTransfer (Ax2012)
InventTransOriginAssemblyComponent (Ax2012)
RecId
RecId
IssueInventTransOrigin (FK,AK1)
ReceiptInventTransOrigin (FK,AK2)
ComponentInventTransOrigin (FK,AK1)
AssemblyInventTransOrigin (FK)
4
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
Refactoring
InventTransId
TransType
This field has been moved to the new InventTransOrigin table and is
renamed ReferenceCategory.
TransRefId
This field has been moved to the new InventTransOrigin table and is
renamed ReferenceId.
InventTransIdTransfer
Direction
This field was redundant (can be deduced from the Qty field) and has
been removed.
InventTransIdFather
ItemRouteId
ItemBomId
InventTransIdReturn
CustVendAC
This field has been replaced by the Party field in the new
InventTransOrigin table. The field has a relationship to the DirParty table.
AssetId
This field has been removed because the table AssetInventTrans already
exists and its InventTransId field has been replaced with a reference to
the new InventTransOrigin table.
AssetBookId
This field has been removed because the tablee AssetInventTrans already
exists and its InventTransId field has been replaced with a reference to
the new InventTransOrigin table.
InventRefTransId
ProbabilityId
5
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
Design Patterns
Add the fields from the new data model to your data model. Prefix the deleted existing
InventTransId fields with DEL_.
Create a data upgrade script to populate the new fields from the old fields. Note that parts of
the data upgrade (validation parts) are done on the source system (the old version being
upgraded from). This is done to shorten the downtime during the upgrade.
Update the user interface to use the new controls appropriate for the pattern defined. The new
controls will leverage the new foreign keys that you added to your data model.
Update the references and business logic in your X++ classes, table methods, and all other
code to use the new design patterns defined in the Design patterns section of this document.
Design patterns
This section discusses how to implement refactoring for Microsoft Dynamics AX 2012. If you need to
refer to the physical model for the tables, see the Data model changes earlier in this document.
== salesLine.InventTransId
inventTrans.InventTransOrigin == inventTransOriginSalesLine.InventTransOrigin
{
info(inventTrans.toString());
}
This change also affects other objects that used the InventTransId field to find, collect, or summarize
data from the InventTrans table.
Existing tables such as SalesLine still have an InventTransId field. However, we strongly recommend
that you use the InventTrans <OriginatingTable> (InventTransSalesLine) table to reference the
6
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
InventTransOrigin table instead of using the InventTransId field of the <OrginatingTable> (SalesLine)
table.Eventually we will be able to remove the InventTransId fields from the inventory transaction
originating tables, and if you rely on those InventTransId fields, you will have to update your code
again.
7
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
Conclusion
This white paper has shown you how to implement the changes to the InventTrans table when
developing new features or updating existing features. Using the new design pattern, you can
implement relationships between the InventTrans table and inventory transaction originating tables
resulting in a reduced amount of data stored (disk space) to avoid redundant data and the inherent
risk of inconsistent data.
8
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS
Microsoft Dynamics is a line of integrated, adaptable business management solutions that enables you and your
people to make business decisions with greater confidence. Microsoft Dynamics works like and with familiar
Microsoft software, automating and streamlining financial, customer relationship and supply chain processes in a
way that helps you drive business success.
U.S. and Canada Toll Free 1-888-477-7989
Worldwide +1-701-281-6500
www.microsoft.com/dynamics
This document supports a preliminary release of a software product that may be changed substantially prior to final commercial
release. This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in
this document. Information in this document, including URL and other Internet Web site references, is subject to change without
notice. The entire risk of the use or the results from the use of this document remains with the user. Unless otherwise noted, the
companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples
herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person,
place, or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user.
Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval
system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any
purpose, without the express written permission of Microsoft Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject
matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this
document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.
2011 Microsoft Corporation. All rights reserved.
Microsoft, the Microsoft Dynamics Logo, Microsoft Dynamics, MorphX, SQL Server, Visual C#, Visual Studio, and Windows are
trademarks of the Microsoft group of companies.
All other trademarks are property of their respective owners.
9
IMPLEMENTING INVENTTRANS REFACTORING FOR MICROSOFT DYNAMICS AX 2012 APPLICATIONS