D365FO – AX – Creating transfer order through X++ code

To create a transfer oder via a code:

inventTransferTable.clear();
inventTransferTable.initValue();
numberSequenceReference = InventParameters::numRefTransferId();
numberSeq =
numberSeq::newGetNumFromCode(numberSequenceReference.NumberSequence);
inventTransferTable.TransferId = numberSeq.num();
inventTransferTable.InventLocationIdFrom = fromloc;
inventTransferTable.modifiedField(fieldNum(InventTransferTable,InventLocationIdFrom));
inventTransferTable.InventLocationIdTo = toloc;
inventTransferTable.modifiedField(fieldNum(InventTransferTable,InventLocationIdTo));
inventTransferTable.TransferStatus = InventTransferStatus::Created;
inventTransferTable.insert();

inventTransferLine.clear();
inventTransferLine.initFromInventTransferTable(inventTransferTable,
NoYes::Yes);
nventTransferLine.ItemId = item;
inventTransferLine.initFromInventTable(InventTable::find(item));
inventTransferLine.QtyTransfer = qty_ship;
inventTransferLine.QtyShipNow = 0;
inventTransferLine.QtyReceiveNow = 0;

inventTransferLine.QtyRemainReceive = qty_ship ;

inventTransferLine.QtyRemainShip = qty_ship ;

inventTransferLine.insert();

Also set the two fields:
QtyRemainShip and QtyRemainReceive to the value of QtyTransfer when you create the line.

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 )

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