18 Mar 2016

Create Transfer Order through code + AX 2012

Today I came to across one requirement like Create transfer order through code.

I find out some useful code  and try to use that  code. It's working fine means i am able to create transfer order.

see below code for your reference.

























Code

static void Job11(Args _args)
{
    InventTransferTable     inventTransferTable;
    InventTransferLine      inventTransferLine;
    NumberSequenceReference     numberSequenceReference;
    NumberSeq       numberSeq;
    ProdBOM    prodBOM;
    InventTable   inventTable;
    ;
    ttsBegin;
    inventTransferTable.clear();
    inventTransferTable.initValue();
    inventTransferTable.TransferId = "000021";
    inventTransferTable.InventLocationIdFrom = "32";
    inventTransferTable.modifiedField(fieldNum(InventTransferTable,InventLocationIdFrom));
    inventTransferTable.InventLocationIdTo = "11";
    inventTransferTable.modifiedField(fieldNum(InventTransferTable,InventLocationIdTo));
    inventTransferTable.TransferStatus = InventTransferStatus::Created;
    inventTransferTable.initFromAddress();
    inventTransferTable.initValue();
    inventTransferTable.initToAddress();
    inventTransferTable.insert();

    if(inventTransferTable)
    {
        inventTransferLine.clear();
        inventTransferLine.initFromInventTransferTable(inventTransferTable,
        NoYes::Yes);
        inventTransferLine.ItemId = "A0001";
        inventTable = InventTable::find(InventTransferLine.ItemId);
        inventTransferLine.initFromInventTable(InventTable);
        inventTransferLine.initFromInventTable(InventTable::find("A0001"));
        inventTransferLine.initFromInventTransferTable(inventTransferTable,false);
        inventTransferLine.QtyTransfer = 2;
        inventTransferLine.QtyShipNow = 0;
        inventTransferLine.QtyReceiveNow = 0;
        inventTransferLine.QtyRemainShip = 1;
        inventTransferLine.QtyRemainReceive = 1;
        inventTransferLine.insert(NoYes::Yes);
    }
    ttsCommit;

}

Successfully created but I find out some issues like
1) when I am try to posting,  posting buttons disabled. But when I try to create transfer order from
     Front end its showing buttons.

2)  In the same form TaxInformation also not updating.

For your reference see below screens.

Through code created Transfer Order.











From front end Created Transfer Order.











I started debugging for the solution.

This is because of when we creating transfer order  missed some reference tables.
So later I added that piece of code, now its working fine as per my expectation.






Code

 inventTransferLine_IN.InventTransferLine = inventTransferLine.RecId;
 inventTransferLine_IN.FromTaxInformation =        TaxInformation_IN::findDefaultbyLocation(inventTransferTable.fromLocation()).RecId;
        inventTransferLine_IN.insert();

I hope it will useful simebody.

Happy DAXing....


No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...