Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Code does not execute correctly

Posted on by 5

Dear fellow members,
I'm working on a class which purpose is to automatically settle GeneralJournalAccountEntry transactions (LedgerTransSettlementForm). I wrote the perfect code and works in ever test case possible BUT the problem is when I truncate the LedgerTransSettlement Table (just to make sure everything works again), so the number of unsettled ledger trans records becomes relatively higher (500 transactions), an issue comes up: My code only settles like 80% of the transactions, when i reopen the LedgerTransSettlement form i find some unsettled transactions so i have to execute my code once more to settle them (and it works too). I dont really know why it stops and never finishes them all at once.
Obviously I have make sure my code Executes CORRECTLY and settles all transaction at the same time (no matter how big their number is).

Can you guys help me solve this ?
Thanks

while select    _generalJournalAccountEntry
    where       _generalJournalAccountEntry.PostingType == LedgerPostingType::PurchPckSlpPurchaseOffsetAccount
    notExists join ledgerTransSettlement
    where       _generalJournalAccountEntry.RecId       == ledgerTransSettlement.TransRecId
{
    --Settlement--
}

  • RE: Code does not execute correctly

    Hey André, this is the entire code i wrote.

    I created two containers, one for the PackingSlipJour(conPS) an the other for the matching Invoices(conInv), then, in the second method I selected for each element in the container the GeneralJournalAccountEntry and put them all in one container(conGJAE) then as a last step I settled all GJAEs in the container.

    public void run()

    {

       while select _generalJournalAccountEntry order by LedgerAccount desc

           where   _generalJournalAccountEntry.PostingType == LedgerPostingType::PurchPckSlpPurchaseOffsetAccount

           /*notExists join ledgerTransSettlement

           where   _generalJournalAccountEntry.RecId       == ledgerTransSettlement.TransRecId*/

       {

           if(!LedgerTransSettlement::findTransRecId(_generalJournalAccountEntry.RecId))

           {

               select      _vendPackingSlipJour

                   join    _generalJournalEntry

                   where   _generalJournalEntry.RecId                          == _generalJournalAccountEntry.GeneralJournalEntry

                   join subledgerVoucherGeneralJournalEntry

                   join    _vendPackingSlipVersion

                   where _vendPackingSlipVersion.VendPackingSlipJour           == _vendPackingSlipJour.RecId

                   &&  (   _vendPackingSlipVersion.LedgerVoucher               ==  subledgerVoucherGeneralJournalEntry.Voucher

                           || subledgerVoucherGeneralJournalEntry.Voucher      ==  _vendPackingSlipVersion.CostLedgerVoucher   )

                   &&  _vendPackingSlipVersion.AccountingDate                  ==  subledgerVoucherGeneralJournalEntry.AccountingDate

                   && subledgerVoucherGeneralJournalEntry.GeneralJournalEntry  ==  _generalJournalEntry.RecId;

               if(_vendPackingSlipJour)

               {

                   conPS+=_vendPackingSlipJour.RecId;

                   for(k=1;k<=conLen(conPS);k++)

                   {

                       _vendPackingSlipJour=VendPackingSlipJour::findRecId(conPeek(conPS,k));

                       while select _vendPackingSlipTrans

                           where   _vendPackingSlipJour.RecId                                      ==  _vendPackingSlipTrans.VendPackingSlipJour

                           join    _vendInvoiceTrans

                           join    PackingSlipSourceDocumentLine,InvoiceSourceDocumentLIne from _vendInvoicePackingSlipQuantityMatch

                           where   _vendPackingSlipTrans.SourceDocumentLine                        ==  _vendInvoicePackingSlipQuantityMatch.PackingSlipSourceDocumentLine

                           &&      _vendInvoicePackingSlipQuantityMatch.InvoiceSourceDocumentLIne  ==  _vendInvoiceTrans.SourceDocumentLine

                           join    _vendInvoiceJour

                           where   _vendInvoiceJour.InvoiceAccount                                 ==  _vendPackingSlipJour.InvoiceAccount

                           &&      _vendInvoiceTrans.PurchId                                       ==  _vendInvoiceJour.PurchId

                           &&      _vendInvoiceTrans.InvoiceId                                     ==  _vendInvoiceJour.InvoiceId

                           &&      _vendInvoiceTrans.InvoiceDate                                   ==  _vendInvoiceJour.InvoiceDate

                           &&      _vendInvoiceTrans.numberSequenceGroup                           ==  _vendInvoiceJour.numberSequenceGroup

                           &&      _vendInvoiceTrans.InternalInvoiceId                             ==  _vendInvoiceJour.InternalInvoiceId

                       {

                           if(!conFind(conInv,_vendInvoiceJour.RecId))

                           {

                               conInv+=_vendInvoiceJour.RecId;

                           }

                       }

                   }

                   for (k=1;k<=conLen(conInv);k++)

                   {

                       _vendInvoiceJour=VendInvoiceJour::findRecId(conPeek(conInv,k));

                       while select _vendPackingSlipTrans

                           join _vendInvoiceTrans

                           where   _vendInvoiceTrans.PurchId                                       ==  _vendInvoiceJour.PurchId

                           &&      _vendInvoiceTrans.InvoiceId                                     ==  _vendInvoiceJour.InvoiceId

                           &&      _vendInvoiceTrans.InvoiceDate                                   ==  _vendInvoiceJour.InvoiceDate

                           &&      _vendInvoiceTrans.numberSequenceGroup                           ==  _vendInvoiceJour.numberSequenceGroup

                           &&      _vendInvoiceTrans.InternalInvoiceId                             ==  _vendInvoiceJour.InternalInvoiceId

                           join PackingSlipSourceDocumentLine,InvoiceSourceDocumentLIne from _vendInvoicePackingSlipQuantityMatch

                           where   _vendPackingSlipTrans.SourceDocumentLine                        ==  _vendInvoicePackingSlipQuantityMatch.PackingSlipSourceDocumentLine

                           &&      _vendInvoicePackingSlipQuantityMatch.InvoiceSourceDocumentLIne  ==  _vendInvoiceTrans.SourceDocumentLine

                           join    _vendPackingSlipJour

                           where   _vendPackingSlipJour.RecId                                      ==  _vendPackingSlipTrans.VendPackingSlipJour

                           &&      _vendInvoiceJour.InvoiceAccount                                 ==  _vendPackingSlipJour.InvoiceAccount

                       {

                           if(!conFind(conPS,_vendPackingSlipJour.RecId))

                           {

                               conPS+=_vendPackingSlipJour.RecId;

                           }

                       }

                   }

                   for(k=1;k<=conLen(conPS);k++)

                   {

                       _vendPackingSlipJour=VendPackingSlipJour::findRecId(conPeek(conPS,k));

                       while select _vendPackingSlipTrans

                           where   _vendPackingSlipJour.RecId                                      ==  _vendPackingSlipTrans.VendPackingSlipJour

                           join    _vendInvoiceTrans

                           join    PackingSlipSourceDocumentLine,InvoiceSourceDocumentLIne from _vendInvoicePackingSlipQuantityMatch

                           where   _vendPackingSlipTrans.SourceDocumentLine                        ==  _vendInvoicePackingSlipQuantityMatch.PackingSlipSourceDocumentLine

                           &&      _vendInvoicePackingSlipQuantityMatch.InvoiceSourceDocumentLIne  ==  _vendInvoiceTrans.SourceDocumentLine

                           join    _vendInvoiceJour

                           where   _vendInvoiceJour.InvoiceAccount                                 ==  _vendPackingSlipJour.InvoiceAccount

                           &&      _vendInvoiceTrans.PurchId                                       ==  _vendInvoiceJour.PurchId

                           &&      _vendInvoiceTrans.InvoiceId                                     ==  _vendInvoiceJour.InvoiceId

                           &&      _vendInvoiceTrans.InvoiceDate                                   ==  _vendInvoiceJour.InvoiceDate

                           &&      _vendInvoiceTrans.numberSequenceGroup                           ==  _vendInvoiceJour.numberSequenceGroup

                           &&      _vendInvoiceTrans.InternalInvoiceId                             ==  _vendInvoiceJour.InternalInvoiceId

                       {

                           if(!conFind(conInv,_vendInvoiceJour.RecId))

                           {

                               conInv+=_vendInvoiceJour.RecId;

                           }

                       }

                   }

                   if (conLen(conPS) && conLen(conInv))

                   {

                       nb += this.LettrageBLFF(conPS,conInv);

                   }

               }

               conPS=conDel(conPS,1,conLen(conPS));

               conInv=conDel(conInv,1,conLen(conInv));

           }

       }

       if(nb)

           info("Lettrage éffectué.");

       else

           info("Aucun lettrage n'a été éffectué.");

    }

    public int LettrageBLFF(container   conPckSlp, container   conInvoice)

    {

       settlementCollection = new RecordInsertList(tablenum(LedgerTransSettlement));

       for (i=1;i<=conLen(conPckSlp);i++)

       {

           _vendPackingSlipJour=VendPackingSlipJour::findRecId(conPeek(conPckSlp,i));

           while select gjaeCr

               where   gjaeCr.PostingType                  ==      LedgerPostingType::PurchPckSlpPurchaseOffsetAccount

               join gjeCr

               where   gjaeCr.GeneralJournalEntry          ==      gjeCr.RecId

               &&      gjeCr.DocumentNumber                ==      _vendPackingSlipJour.PackingSlipId

               &&      gjeCr.AccountingDate                ==      _vendPackingSlipJour.DeliveryDate

               notexists join ledgerTransSettlement

               where   gjaeCr.RecId                        ==      ledgerTransSettlement.TransRecId

           {

               if(!conFind(conGJAE,gjaeCr.RecId))

               {

                   conGJAE+=gjaeCr.RecId;

                   sumGJAECr += gjaeCr.AccountingCurrencyAmount;

               }

           }

       }

       for(i=1;i<=conLen(conInvoice);i++)

       {

           _vendInvoiceJour=VendInvoiceJour::findRecId(conPeek(conInvoice,i));

           while select gjaeDeb

               where   gjaeDeb.PostingType                 ==      LedgerPostingType::PurchPckSlpPurchaseOffsetAccount

               join gjeDeb

               where   gjaeDeb.GeneralJournalEntry         ==      gjeDeb.RecId

               &&      gjeDeb.DocumentNumber               ==      _vendInvoiceJour.InvoiceId

               &&      gjeDeb.AccountingDate               ==      _vendInvoiceJour.InvoiceDate

               &&      gjeDeb.SubledgerVoucher             ==      _vendInvoiceJour.LedgerVoucher

               notexists join ledgerTransSettlement

               where   gjaeDeb.RecId                       ==      ledgerTransSettlement.TransRecId

           {

               if(!conFind(conGJAE,gjaeDeb.RecId))

               {

                   conGJAE+=gjaeDeb.RecId;

                   sumGJAEDeb += gjaeDeb.AccountingCurrencyAmount;

               }

           }

       }

       if(sumGJAEDeb+sumGJAECr==0)

       {

           ledgerTransSettlement.SettleId           = NumberSeq::newGetNum(CompanyInfo::numRefParmId()).num();

           for(i=1;i<=conLen(conGJAE);i++)

           {

               ledgerTransSettlement.TransRecId         = conPeek(conGJAE,i);

               settlementCollection.add(ledgerTransSettlement);

           }

           settlementCollection.insertDatabase();

           return conLen(conGJAE);

       }

       conGJAE=conDel(conGJAE,1,conLen(conGJAE));

       sumGJAEDeb=0;sumGJAECr=0;

       return 0;

    }

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    RE: Code does not execute correctly

    Hi AmineNaija,

    What exactly did you use as coding in the --Settlement-- part? Is there a skip based on a certain condition?

    Another concern from my side: Based on what decision do you create the settlement record? Are you really settling at least two matching records (debit equals to credit with multiple records)?

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans