Transfer Orders Import

Microsoft Dynamics AX 2012 Xpp –
Transfer Orders Import
 
Purpose: The purpose of this document is to illustrate how to write a required minimum X++ code in Microsoft Dynamics AX 2012 in order to import Transfer orders.
 
Challenge: Data model changes in Microsoft Dynamics AX 2012 related to high normalization and introduction of surrogate keys made some imports more complex. However the structure of tables comprising Transfer order header/lines didn't change. Please note that after you import Transfer orders you may need to perform Ship and Receive operations if required (for example, for Transfer orders already in execution).
 
Solution: Appropriate tables buffers (InventTransferTable, InventTransferLine) will be used when writing X++ code in Microsoft Dynamics AX 2012 in order to import Transfer orders. Alternatively AxBC classes may be used instead of table buffers.
 
Data Model:
 
Table Name
Table Description
InventTransferTable
The InventTransferTable table contains information about transfer orders.
InventTransferLine
The InventTransferLine table contains information about items that are transferred from one warehouse to another by using a transfer order.
InventDim
The InventDim table contains values for inventory dimensions.
 
Data Model Diagram:
<![if !vml]><![endif]>
 
Development:
 
ttsBegin: Use ttsBegin to start a transaction.
 
clear: The clear method clears the contents of the record.
 
initValue: The initValue method initializes the fields of the record.
initFrom*: The initFrom* methods usually populate the fields of the child record based on the fields on the parent record. Example is initFromInventTransferTable method on InventTransferLine table.
 
validateWrite: The validateWrite method checks whether the record can be written.
write: The write method writes the record to the database.
 
insert: The insert method inserts the record into the database.
doInsert: The doInsert method inserts the record into the database. Calling doInsert ensures that any X++ code written in the insert method of the record is not executed. Calling insert always executes the X++ code written in the insertmethod of the record.
 
ttsCommit: Use ttsCommit to commit a transaction.
 
Source code:
 
static void TransferOrdersXppImport(Args _args)
{
    #define.WarehouseFrom("11")
    #define.WarehouseTo("12")
    #define.ShipDate("1/1/2014")
    #define.ReceiveDate("1/1/2014")
    #define.ItemId("M0001")
    #define.Qty(1)
    #define.Site("1")
    #define.Warehouse("11")
 
    InventTransferTable     inventTransferTable;
    InventTransferLine      inventTransferLine;
    InventDim               inventDim;
 
    try
    {
        ttsbegin;
 
        //Order header
        inventTransferTable.clear();
        inventTransferTable.initValue();
        inventTransferTable.TransferId = InventTransferTable::numberSeq().num();
        inventTransferTable.InventLocationIdFrom = #WarehouseFrom;
        inventTransferTable.InventLocationIdTo = #WarehouseTo;       
        inventTransferTable.DlvModeId = CustVendTransportPointLine::defaultDeliveryMode(inventTransferTable.InventLocationIdFrom,'','','','',inventTransferTable.InventLocationIdTo);
        inventTransferTable.InventLocationIdTransit = InventLocation::find(inventTransferTable.InventLocationIdFrom).InventLocationIdTransit;
        inventTransferTable.initFromAddress();
        inventTransferTable.initToAddress();
 
        inventTransferTable.ShipDate = str2Date(#ShipDate, 213);
        inventTransferTable.ReceiveDate = str2Date(#ReceiveDate, 213);
 
        if (inventTransferTable.validateWrite())
        {
            inventTransferTable.insert();
 
            //Order line
            inventDim.clear();
            inventDim.InventSiteId = "1";
            inventDim.InventLocationId = "12";
 
            inventTransferLine.clear();
            inventTransferLine.initValue();
 
            inventTransferLine.ItemId = #ItemId;
            inventTransferLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
            inventTransferLine.QtyTransfer = #Qty;
 
            inventTransferLine.initFromInventTableModule(InventTableModule::find(inventTransferLine.ItemId,ModuleInventPurchSales::Invent));
 
            inventTransferLine.QtyRemainReceive = inventTransferLine.QtyTransfer;
            inventTransferLine.QtyRemainShip = inventTransferLine.QtyTransfer;
 
            inventTransferLine.ShipDate = str2Date(#ShipDate, 213);
            inventTransferLine.ReceiveDate = str2Date(#ReceiveDate, 213);
 
            inventTransferLine.initFromInventTransferTable(inventTransferTable, false);
            inventTransferLine.LineNum = InventTransferLine::lastLineNum(inventTransferLine.TransferId) +1.0;
 
            if (inventTransferLine.validateWrite())
            {
                inventTransferLine.insert();
            }
            else
                throw error("Order line");
        }
        else
            throw error("Order header");
 
        ttscommit;
    }
    catch
    {
        error("Error!");
        return;
    }
 
    info("Done!");
}
 
Result:
 
Warehouse
 
 
Please note that Transit Warehouse is assigned on From Warehouse record
 
Transfer order header and lines
 
Ship
 
Receive
 
Inventory transactions
 
Note: Microsoft Dynamics AX 2012 Demo Data (Company USMF) was used for this example
 
Version: Microsoft Dynamics AX 2012 RTM, R2
 
Summary: In this document I explained how to write a required minimum X++ code in Microsoft Dynamics AX 2012 in order to import Transfer orders. Appropriate table buffers were used when writing X++ code in Microsoft Dynamics AX 2012. This approach can be very handy for POC's or in situation with always changing requirements. You can also use Microsoft Dynamics AX Excel Add-in to import relatively small amounts of data. Please consider using DIXF (Data Import Export Framework) for import of significant amounts of data when performance is an important consideration. DIXF (Data Import Export Framework) provides a standard template for import of Transfer orders.
 

Comments