Monday, February 22, 2021

Create Transfer Order using X++ in d365fo

 Create Transfer Order using X++ in d365fo.


static void CreateTransferOrder(Args _args)

{

    inventTransferTable inventTransferTable;

    inventTransferLine inventTransferLine;

    numberSequenceReference numberSequenceReference;

    numberSeq numberSeq;

    ProdBom   prodBom;

    InventTable  inventTable;

;

    ttsBegin;

    numberSeq = NumberSeq::newGetNum(InventParameters::numRefTransferId());

    inventTransferTable.clear();

    inventTransferTable.initValue();

   // inventTransferTable.TransferId='000021';


    inventTransferTable.TransferId = numberSeq.num();

    numberSeq.used();

    // inventTransferTable.InventDim

    inventTransferTable.InventLocationIdFrom = '11';

    inventTransferTable.modifiedField(fieldNum(InventTransferTable, InventLocationIdFrom));

    inventTransferTable.InventLocationIdTo = '13';

    inventTransferTable.modifiedField(fieldNum(InventTransferTable, InventLocationIdTo));

    inventTransferTable.TransferStatus = InventTransferStatus::Created;

    inventTransferTable.insert();


//Line

    inventTransferLine.clear();


    inventTransferLine.ItemId = 'D0001';

    inventTransferLine.initFromInventTable(InventTable::find('D0001'));

    inventTransferLine.initFromInventTransferTable(inventTransferTable, NoYes::Yes);

    inventTransferLine.QtyTransfer = 10;

    inventTransferLine.QtyShipNow = 10;

    inventTransferLine.QtyReceiveNow = 10;

    inventTransferLine.insert();

    ttsCommit;

    info(strFmt("%1",inventTransferTable.TransferId));

}


-----------or--------------------

static void CreateTransferOrderLine(Args _args)

{


InventTransferTable inventTransFerTable;

InventTransferLine inventTransFerLine;

InventTable inventTable;

NumberSeq numberSeq;

ttsBegin;

numberSeq = NumberSeq::newGetNum(InventParameters::numRefTransferId());


inventTransferTable.TransferId = numberSeq.num();

numberSeq.used();

inventTransferTable.InventLocationIdFrom = "13";

inventTransferTable.InventLocationIdTo = "11";


inventTransferTable.InventLocationIdTransit = InventLocation::find(inventTransferTable.InventLocationIdFrom).InventLocationIdTransit;

inventTransferTable.initFromAddress();

inventTransferTable.initValue();

inventTransferTable.initDeliveryMode();

inventTransferTable.initToAddress();

inventTransferTable.insert();

inventTransferLine.clear();


inventTransferLine.initFromInventTransferTable(inventTransferTable,NoYes::Yes);

inventTransferLine.ItemId = "D0001";

inventTransFerLine.LineNum = InventTransferLine::lastLineNum(inventTransferTable.TransferId) + 1;

inventTable = InventTable::find(InventTransferLine.ItemId);

inventTransferLine.initFromInventTable(InventTable);

inventTransferLine.QtyTransfer = 1.0;

inventTransferLine.QtyRemainReceive = 1.0;

inventTransferLine.QtyRemainShip = 1.0;

inventTransferLine.insert();

ttsCommit;

info(strFmt("%1",inventTransferTable.TransferId));

}

Keep Daxing!!

No comments:

Post a Comment