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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

My looping only return same invoice number although have multiple invoices in a journal

(0) ShareShare
ReportReport
Posted on by

Hi all,

i tested by using 1 journal that have 2 invoices.however, it will give output as 2 invoice but second invoice is same information with first invoice. i know my looping is wrong but i dont know how to fix it already. i use debugger, it loop at the underline code below,but when it loop for second invoice, it not return the correct value as it only copy the first invoice value.

protected container outputPaymAdvice(VendOutPaymRecord   _clsVendOutPaymRecord, container gconRecord)

{

   #define.space(' ')

   VendPaymModeTable       tblPaymMode;

   LedgerJournalTable     tblLedgerJournalTable;

   LedgerJournalTrans     tblLedgerJournalTrans;

   VendTrans               vendTrans;

   str                    strRecord;

   str                     strFileRef;

   BankAccountTable       tblBank;

   SpecTrans               tblSpecTrans,tblSpecTransCheck;

   str     strFileName = "";

   ;

   tblPaymMode = VendPaymModeTable::find(_clsVendOutPaymRecord.parmCustVendPaym().ledgerJournalTrans().PaymMode);

   tblBank = _clsVendOutPaymRecord.parmCustVendPaym().bankAccountTable();

   tblLedgerJournalTrans = _clsVendOutPaymRecord.parmCustVendPaym().ledgerJournalTrans();

 

   select tblSpecTransCheck

       where tblSpecTransCheck.SpecTableId == tblLedgerJournalTrans.TableId &&

             tblSpecTransCheck.SpecRecId == tblLedgerJournalTrans.RecId &&

             tblSpecTransCheck.SpecCompany == tblLedgerJournalTrans.Company;

 

   if(tblSpecTransCheck)

   {

       while select tblSpecTrans

       where tblSpecTrans.SpecTableId == tblLedgerJournalTrans.TableId &&

             tblSpecTrans.SpecRecId == tblLedgerJournalTrans.RecId &&

             tblSpecTransCheck.SpecCompany == tblLedgerJournalTrans.Company

             if (tblSpecTrans.vendTrans().Invoice)//for Payment Advice fix format

             {

                   //1:   RECORD TYPE. Format: 9(1)   Range: 1-1     Mandatory: Y Remark : Payment Advice fix format

                   strRecord += strLFix("3", 1) ;

 

                   //2:   Spacing Line.   Format: X(20). Range: 2-4. Mandatory: Y.

                   strRecord += strupr(strrep(#space,2));

 

                   //3:   Invoice no.   Format: x(20). Range: 4-24. Mandatory: Y.

                   strRecord += strLFix(tblSpecTrans.vendTrans().Invoice, 20);

 

                   //4:    Invoice Date.   Format: 9(8). Range: 24-32. Mandatory: N.

                   strRecord += SKMY_BankIntgrUtilUOB_ANT::convertDate2str(tblSpecTrans.vendTrans().TransDate);

 

                   //5:   Invoice Amount.   Format: 9(9)V9(2). Range: 32-43. Mandatory: N.

                   strRecord += SKMY_BankIntgrUtilUOB_ANT::real2NumChar(-tblSpecTrans.Balance01, 11, true);

 

                   //6:   Gross Amount.   Format: 9(9)V9(2). Range: 43-20. Mandatory: N.

                   strRecord += strupr(strrep(#space,11));

 

                   //7:   Discount.   Format: 9(9)V9(2). Range: 54-20. Mandatory: N.

                   strRecord += strupr(strrep(#space,4));

 

                   //8:   Positive or Negetive sign.   Format: x(1). Range: 58-59. Mandatory: Y.

                     if (-tblSpecTrans.Balance01 >= 0)

                       {

                       strRecord += strLFix("+", 1);

                       }

                     else if (-tblSpecTrans.Balance01 < 0)

                       {

                       strRecord += strLFix("-", 1);

                       }

                     //9:   Item code.   Format: x(30). Range: 59-89. Mandatory: N.

                   strRecord += strupr(strrep(#space,30));

 

                 //10:   Item description line 1.     Format: x(35). Range: 89-124. Mandatory: N.

                   strRecord += strupr(strrep(#space,35));

 

                   //11:   Item description line 2.     Format: x(35). Range: 124-159. Mandatory:N.

                   strRecord += strupr(strrep(#space,35));

 

                   //12:   Item description line 3.     Format: x(35). Range: 159-194. Mandatory: N.

                   strRecord += strupr(strrep(#space,35));

 

                   //13:   Filler   Format: x(1609). Range: 194-1609. Mandatory: Blanks

                   //strRecord += strupr(strrep(#space,1609));

 

                   gconRecord = conins(gconRecord, conlen(gconRecord) + 1, strRecord);

             }

   }

   else

   {

 

       //1:   RECORD TYPE. Format: x(1)   Range: 1-2     Mandatory: Y Remark : Payment Advice Freetext

       strRecord = strLFix("4", 1) ;

 

       //2:   Spacing Line.   Format: 9(2). Range: 2-4. Mandatory: Y.

       strRecord += strupr(strrep(#space,2));

 

       //3:   Payment Advice Details.   Format: x(105). Range: 4-109. Mandatory: Y.

       strRecord += strLFix(tblLedgerJournalTrans.txt, 105);

 

       //4:   Filler   Format: x(1694). Range: 109-1803. Mandatory: Blanks

       //strRecord += strupr(strrep(#space,1609));

       gconRecord = conins(gconRecord, conlen(gconRecord) + 1, strRecord);

     }

   return gconRecord;

}

*This post is locked for comments

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

    Most of the code above doesn't look related to the problem. You should have throw away everything unrelated; it would make your testing much easier (now you have go through many things irrelevant to what you're debugging) and it be much easier for others to understand it too.

    First of all, use the debugger to find out whether tblSpecTransCheck is filled in. It will tell you which part of the if/else statement is used and you can ignore the other. If you get into the "if" part, check whether the "while select" returns the right records. If not, you've found the bug. It if does, you have a bug in the later code (e.g. when inserting to the container) and you must continue debugging.

    By the way, why are you using a container? Don't you find it difficult (and error-prone) to work with?

  • Community Member Profile Picture
    on at

    thanks martin.will do as your advice

  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at

    By the way, I've noticed that the last condition in the select statement is using different tables than what you're selecting. You're selecting data from tblSpecTrans, but you're comparing tblSpecTransCheck and tblLedgerJournalTrans. It's a likely a bug.

    And you really should use a block (i.e. {}) for the content of the while loop. Omitting it will easily lead to errors.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans