Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Insert transfer journal through x++

Posted on by 570

Hello ..

i want to insert about 1000 lines in one journal , so i found the next code and it help me to insert one line 

but i need to insert 1000 liens from another ax table 
Original code is 

static void CreateTransferJournal(Args _args)
{
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
InventJournalCheckPost inventJournalCheckPost;
NumberSeq num;
boolean _throwserror=true;
boolean _showinforesult=true;
InventDim frominventDim,ToinventDim;
;
ttsbegin; 
inventJournalTable.clear();
num = new NumberSeq();
num = NumberSeq::newGetNum
(InventParameters::numRefTransferId());
inventJournalTable.initFromInventJournalName(InventJournalName::find
(InventParameters::find().TransferJournalNameId));
inventJournalTable.Description = “Inventory Transfer Journal”;
inventJournalTable.SystemBlocked = true;
inventJournalTable.insert(); 
inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.ItemId = “xxxxxx”;
frominventDim.InventLocationId=”xx”;
frominventDim.inventSiteId =”xx”;
ToinventDim.InventLocationId = “xxxx”;
ToinventDim.InventSiteId = “xx”;
ToinventDim = InventDim::findOrCreate(ToinventDim); 
frominventDim = InventDim::findOrCreate(frominventDim); 
inventJournalTrans.InventDimId = frominventDim.inventDimId;
inventJournalTrans.initFromInventTable(InventTable::find(“1101″));
inventJournalTrans.Qty = 10;
inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
inventJournalTrans.TransDate = SystemDateget();
inventJournalTrans.insert(); 
inventJournalCheckPost =
InventJournalCheckPost::newJournalCheckPost
(JournalCheckpostType::Post,inventJournalTable);
inventJournalCheckPost.parmThrowCheckFailed(_throwserror);
inventJournalCheckPost.parmShowInfoResult(_showinforesult);
inventJournalCheckPost.run(); 
inventJournalTable.SystemBlocked = false;
inventJournalTable.update(); 
ttscommit;
}

so now i edited the code and added while select from the other table

static void CopyOfCreateTransferJournal(Args _args)
{
    aaaT                     aaa1;
    InventJournalTable      inventJournalTable;
    InventJournalTrans      inventJournalTrans;
    InventJournalCheckPost  inventJournalCheckPost;
    NumberSeq               num;
    boolean                 _throwserror    =   true;
    boolean                 _showinforesult =   true;
    InventDim               frominventDim,ToinventDim;
    ;


    inventJournalTable.clear();
    num = new NumberSeq();
    num = NumberSeq::newGetNum(InventParameters::numRefTransferId());
    inventJournalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().TransferJournalNameId));
    inventJournalTable.Description = 'Inventory Transfer Journal';
    inventJournalTable.SystemBlocked = true;
    inventJournalTable.insert();
    while select * from aaa1
    {
    ttsbegin;
    inventJournalTrans.clear();
    inventJournalTrans.initFromInventJournalTable(inventJournalTable);
    inventJournalTrans.ItemId = aaa1.ItemId;
    frominventDim.InventLocationId = aaa1.InventLocationIdFrom;
    frominventDim.inventSiteId = aaa1.InventSiteIdFrom;
    ToinventDim.InventLocationId = aaa1.InventLocationIdTO;
    ToinventDim.InventSiteId = aaa1.InventSiteIdTo;
    ToinventDim = InventDim::findOrCreate(ToinventDim);
    frominventDim = InventDim::findOrCreate(frominventDim);
    inventJournalTrans.InventDimId = frominventDim.inventDimId;
    inventJournalTrans.initFromInventTable(InventTable::find(aaa1.ItemId));
    inventJournalTrans.Qty = aaa1.Qty;
    inventJournalTrans.ToInventDimId = ToinventDim.inventDimId;
    inventJournalTrans.TransDate = SystemDateget();
    inventJournalTrans.insert();
    //inventJournalTable.SystemBlocked = false;
    //select  forUpdate  inventJournalTable;// where  inventJournalTable.
    //inventJournalTable.update();

    //if(InventJournalCheckPost::newPostJournal(inventJournalTable).validate())
    //InventJournalCheckPost::newPostJournal(inventJournalTable).run();
     ttscommit;
    }



}


Now there is an error after start the job

(Maximum number of decimals for the stockkeeping unit is 8)

thanks

  • Verified answer
    Ismail Mohamed Profile Picture
    Ismail Mohamed 570 on at
    RE: Insert transfer journal through x++

    Thanks the problem was in some data

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,246 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,041 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans