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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Create General Journal

(0) ShareShare
ReportReport
Posted on by 10

Hello , 

How I can insert  multi voucher in the one journal ? 

I'm using this code 

7522.Capture1.PNG

but this code create journal for each transaction 

using d365 f&o

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,684 Most Valuable Professional on at

    You indeed insert a new journal in each iteration. If you want just a single journal with multiple lines, create LedgerJournalTable just once.

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    As Martin wrote, don't create new LedgerJournalTable on each iteration if you don't want to create new LedgerJournalTable for each iteration.

    Additionally the part of the code where you try to initialize something from LedgerJournalName doesn't work.

    You should find LedgerJournalName first, then use the found buffer in LedgerJournalTable.initFromLedgerJournalName.

  • Pionners Profile Picture
    10 on at

    Can you show me where to make the adjustment,

    Because I've only entered LedgerJournalTable once and nothing has changed,

    You have entered the LedgerJournalTable out of loops

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    On your first code line you have a while loop.

    On your tenth code line you insert LedgerJournalTable.

    This means that you create a new journal for each iteration of your loop.

    Please share your code via Use rich text formatting -> Insert -> Code. This way we can refer to line numbers, we can copy-paste parts of it to include in our answers etc.

  • Pionners Profile Picture
    10 on at

    .

  • nmaenpaa Profile Picture
    101,172 Moderator on at

    Please share your code via Use rich text formatting -> Insert -> Code. This way we can refer to line numbers, we can copy-paste parts of it to include in our answers etc. Without this rich formatting we don't have line numbers and it's difficult to read.

    Additionally, if you still have some questions, please let us know. 

  • Pionners Profile Picture
    10 on at

    while(RevenueFromVisTbl)
    
               {
    
                   if(RevenueFromVisTbl.RevenueAmount != 0.0)
    
                   _JournalNamee  = (select JOURNALNAME from VisIntegrationJournalNameDataTbl where  VisIntegrationJournalNameDataTbl.transtype == RevenueFromVisTbl.VehicleCategoryCode).JOURNALNAME  ;
    
                   _RevenueReceiptsNo =any2Str(RevenueFromVisTbl.RevenueReceiptsNo);
    
                   ledgerJournalName.clear();
    
                   ledgerJournalTable.clear();
    
                   ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
    
                   ledgerJournalName = LedgerJournalName::find(_JournalNamee);
    
                   ledgerJournalTable.insert();
    
                   ledgerJournalTrans.JournalNum               = ledgerJournalTable.JournalNum;
    
                   ledgerJournalTrans.Voucher                  = NumberSeq::newGetVoucherFromId(ledgerJournalName.NumberSequenceTable).voucher();
    
                   ledgerJournalTrans.Approved                 = NoYes::Yes;
    
                   ledgerJournalTrans.DocumentNum              = ledgerJournalTable.DocumentNum;
    
                   ledgerJournalTrans.Company                  = RevenueFromVisTbl.DataAreaId;
    
                   ledgerJournalTrans.OffsetCompany            = RevenueFromVisTbl.DataAreaId;
    
                   ledgerJournalTrans.TransactionType = LedgerTransType::GeneralJournal;
    
                   ledgerJournalTrans.AccountType                 = LedgerJournalACType::Ledger;
    
                   if(RevenueFromVisTbl.RefundTransaction == 0 )
    
                   {
    
                       _AccountNumber = LedgerDimensionFacade::getDisplayValueForLedgerDimension(RevenueFromVisTbl::findAccountNum(RevenueFromVisTbl.VehicleCategoryCode ) ) ;
    
                       ledgerJournalTrans.LedgerDimension                = PostData::getLedgerDimension(_AccountNumber , RevenueFromVisTbl.RevenueCostCenter);
    
                       //ledgerJournalTrans.LedgerDimension              =any2Int64( RevenueFromVisTbl::findAccountNum(RevenueFromVisTbl.VehicleCategoryCode) '-' RevenueFromVisTbl.RevenueCostCenter) ;
    
                   }
    
                   else
    
                   {
    
                       ledgerJournalTrans.LedgerDimension             = any2Int64(LedgerDimensionFacade::getDisplayValueForLedgerDimension(RevenueFromVisTbl::findRefundtNum(RevenueFromVisTbl.VehicleCategoryCode ) )  '---');
    
                   }
    
                   ledgerJournalTrans.AmountCurCredit            = abs(RevenueFromVisTbl.RevenueAmount);
    
                   if(RevenueFromVisTbl.Revenue_CustmerID != '' )
    
                   {
    
                       ledgerJournalTrans.OffsetAccountType          = LedgerJournalACType::Cust;
    
                       ledgerJournalTrans.OffsetLedgerDimension    = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(RevenueFromVisTbl::findCusAccountNum(any2Int64(RevenueFromVisTbl.Revenue_CustmerID)) , ledgerJournalTrans.OffsetAccountType);
    
                   }
    
                   else if(RevenueFromVisTbl.Revenue_EmployeeID != '' )
    
                   {
    
                       ledgerJournalTrans.OffsetAccountType          = LedgerJournalACType::Employee;
    
                       //ledgerJournalTrans.OffsetLedgerDimension    = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(RevenueFromVisTbl::findEmpAccountNum(any2Int64(RevenueFromVisTbl.Revenue_EmployeeID)) , ledgerJournalTrans.OffsetAccountType);
    
                   }
    
                   else
    
                   {
    
                       ledgerJournalTrans.OffsetAccountType          = LedgerJournalACType::Bank;
    
                       ledgerJournalTrans.OffsetLedgerDimension    = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(RevenueFromVisTbl::findBankAccount(RevenueFromVisTbl.VehicleCategoryCode) , ledgerJournalTrans.OffsetAccountType);
    
                   }
    
                   ledgerJournalTrans.TransDate                  = RevenueFromVisTbl.RevenueDate;
    
                   ledgerJournalTrans.Due                        = RevenueFromVisTbl.RevenueDate;
    
                   ledgerJournalTrans.CurrencyCode               = 'SAR';
    
                   ledgerJournalTrans.insert();
    
    

  • nmaenpaa Profile Picture
    101,172 Moderator on at

    Great, thanks.

    Additionally, if you still have some questions, please let us know.

  • Pionners Profile Picture
    10 on at

    Where do I adjust to achieve what I want?

  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Move this part out of the while loop (to be executed before the while loop (and fix the LedgerJournalName handling):

    _JournalNamee  = (select JOURNALNAME from VisIntegrationJournalNameDataTbl where  VisIntegrationJournalNameDataTbl.transtype == RevenueFromVisTbl.VehicleCategoryCode).JOURNALNAME  ;
    ledgerJournalName = LedgerJournalName::find(_JournalNamee);
    
    ledgerJournalTable.clear();
    ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
    ledgerJournalTable.insert();

    Do you now understand why it created many journals? Please let us know if you need any more support.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 668 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 630 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 581

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans