Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

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

*This post is locked for comments

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

    Thanks the problem was in some data

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans