Friday, April 15, 2011

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.insert();

Also set the two fields:

QtyRemainShip and QtyRemainReceive to the value of QtyTransfer when you create the line.

1 comment:

Scot Cap said...

This code doesn't work in DAX 2012. Error: on line numberSeq =
numberSeq::newGetNumFromCode(numberSequenceReference.NumberSequence);
error is Table does not contain this field.