D365FO – AX – Posting a Transfer Order using X++

While working with unit testing in AX, I came across the need to generate a transfer order and post it to generate the associated tables. I have used the FormLetter classes for posting Sales Orders & Purchase Orders in the past so I started looking for a similar process for Transfer Orders. I started by examining the code that is used in AX for the same purpose. This search led me to the following information.

For posting Transfer Orders the InventTransferUpd classes are used to post a single Transfer Order, while the InventTransferMulti classes are used to post multiple Transfer Orders in a single run.

The InventTransferUpd classes contain a static method that constructs a new instance using an InventTransferParmTable record to set the posting options. The classes also contain a run() method that performs the actual posting.

The following example demonstrates a potential usage of all three types of the InventTransferUpd classes.

static InventTransferUpd PostTransferOrder(InventTransferParmTable _invTransParmTbl)
    InventTransferUpd    invTranUpd;
        case InventTransferUpdateType::PickingList:
            invTranUpd = InventTransferUpdPick::newParmBuffer(_invTransParmTbl);
        case InventTransferUpdateType::Shipment:
            invTranUpd = InventTransferUpdShip::newParmBuffer(_invTransParmTbl);
        case InventTransferUpdateType::Receive:
            invTranUpd = InventTransferUpdReceive::newParmBuffer(_invTransParmTbl);
            return null;        
    return invTranUpd;    

This method could be called in the following manner:

InventTransferParmTable invTransParmTbl;
invTransParmTbl.TransferId = [TRANSFER ID];
invTransParmTbl.EditLines = true;
invTransParmTbl.AutoReceiveQty = true;
invTransParmTbl.UpdateType = InventTransferUpdateType::PickingList;
invTransParmTbl.PickUpdateQty = InventTransferPickUpdateQty::All;
invTransParmTbl.TransDate = systemDateGet();

This quick solution was sufficient for my need of generating some unit test data, but you can browse the methods and fields of the classes & tables demonstrated here to get a better understanding of which fields may be needed for your particular circumstance.

If you have more information on this topic, I welcome any feedback

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 )

Facebook photo

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

Connecting to %s