web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Insert multiple lines into movement journal

(0) ShareShare
ReportReport
Posted on by 40


//Below code creates journal header
inventJournalTable.clear();
inventJournalName = InventJournalName::standardJournalName(InventJournalType::Movement);
inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName ));
inventJournalTable.insert();

//Below code creates journal lines
inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.TransDate = systemDateGet();
inventJournalTrans.ItemId = itemid;
inventJournalTrans.initFromInventTable(InventTable::find(itemid));
inventJournalTrans.Qty = qty;
inventDim.InventSiteId = 'AVON';
inventDim.InventLocationId = '0001000';
inventDim.wMSLocationId = 'A02';
inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;

if(inventJournalTrans.Qty == 0)
{
numOfLines++;
inventJournalTrans.insert();
}
inventJournalTable.NumOfLines = numOfLines;
inventJournalTable.update();
info(strFmt("Stock Count Journal has been created with Journal Name: %1 and Journal ID: %2", inventJournalName, inventJournalTable.JournalId));

Above is x++ code to create the movement journal, my question is, how do i create same journal id with multiple lines? bcs when i run this code, it will output one 1 line with different journal id

btw, before this code snippet is importing and read record from excel, so when i import 4 rows of record, it will output only 1 line of journal line and all at different journal id? anyone kind to help?

I have the same question (0)
  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    If you want to create a journal per excel sheet, you can have a condition that creates the journal header only the first time and then creates the lines.

    if (!inventJournalTable)
    {
        inventJournalName = InventJournalName::standardJournalName(InventJournalType::Movement);
        inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName ));
        inventJournalTable.insert();
    }
    
    //Below code creates journal lines
    inventJournalTrans.clear();
    inventJournalTrans.initFromInventJournalTable(inventJournalTable);
    inventJournalTrans.TransDate = systemDateGet();
    inventJournalTrans.ItemId = itemid;
    inventJournalTrans.initFromInventTable(InventTable::find(itemid));
    inventJournalTrans.Qty = qty;
    inventDim.InventSiteId = 'AVON';
    inventDim.InventLocationId = '0001000';
    inventDim.wMSLocationId = 'A02';
    inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
    
    if(inventJournalTrans.Qty == 0)
    {
        numOfLines  ;
        inventJournalTrans.insert();
    }
    
    // Call this after all the lines are read from excel and inserted into the movement journal.
    inventJournalTable.NumOfLines = numOfLines;
    inventJournalTable.update();
    info(strFmt("Stock Count Journal has been created with Journal Name: %1 and Journal ID: %2", inventJournalName, inventJournalTable.JournalId));

  • fireblaster Profile Picture
    40 on at

    Nice! it works. at first i thought it doesnt need to put the condition for the header table bcs only required to insert into line table

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans