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 :
Microsoft Dynamics AX (Archived)

Infinite loop

(0) ShareShare
ReportReport
Posted on by

hello, i have a while loop in my code that is loop on records in table and during debug it continue looping for records that doesn't exist in the table and therefore when openning the form related to that method by logic it doesn't respond because of infinite loop

my question is : from where these records that doesn't contained in the table came from

for example i have 100 Record in table and last rec have id with RecId=100 , during debug it's continue for loop for rec id 101 , 102 , 103 ....etc and table just have 100 Rec

*This post is locked for comments

I have the same question (0)
  • Prasad.V Profile Picture
    185 on at

    can you show us your code?

  • Brandon Wiese Profile Picture
    17,788 on at

    Are you inserting records in your loop into that same table?

  • Suggested answer
    Community Member Profile Picture
    on at

    Without knowing all the details,

    I ran into this issue when doing a while select loop on multiple tables.

    I was missing the where clause that "linked", if you will, the inventsum table to the inventtable

    Heres a snippet of my code i hope you can adapt it to get what you need without infinite loops!

        While Select        Itemid, AvailPhysical           from    INVENTSUM 
        JOIN                InventLocationId, wMSLocationId from    INVENTORY
        WHERE               INVENTORY.inventDimId           ==      INVENTSUM.InventDimId
        &&                  INVENTSUM.ItemId                LIKE "*-C"
        &&                  INVENTSUM.AvailPhysical         >= 1
        &&                  INVENTORY.InventLocationId      == "Warehouse1"
        &&                  INVENTORY.wMSLocationId         != ""
        &&                  !(INVENTORY.wMSLocationId       Like "Conveyor*")
        { 
             dostuff;
        }


  • Community Member Profile Picture
    on at

    Also I recommend using threads to prevent window ghosting. Sounds like your table is small now but if it grows in size over time you will run into ghosting if your thread takes more then 5 seconds to process.

  • Community Member Profile Picture
    on at

    ProjTransPosting  projTransPostingOrig,projTransPostingInsert;

    ttsbegin;

       while select forupdate projTransPostingOrig

           where projTransPostingOrig.Voucher == _voucherNo &&

                 projTransPostingOrig.PaymentStatus == ProjPaymentStatus::ExpectedPayment

       {

           // Check to see if the partial payment needs to be done

           if (_partialPayment)

           {

               // Copy the row to be inserted

              projTransPostingInsert.data(projTransPostingOrig);

               // Copy the original amount and qty

               originalQty    = projTransPostingOrig.Qty;

               originalAmount = projTransPostingOrig.AmountMst;

               // get percentage of partial payment

               partialAmount = Currency::amount(originalAmount * _percentagePayment);

               partialQty = decRound(originalQty * _percentagePayment, 2);

               // insert new record

               projTransPostingInsert.AmountMst     = originalAmount - partialAmount;

               projTransPostingInsert.Qty           = originalQty - partialQty;

               projTransPostingInsert.PaymentStatus = ProjPaymentStatus::ExpectedPayment;

               projTransPostingInsert.insert();

               // We need to edit the existing record to reflect the partial payment

               projTransPostingOrig.AmountMst =  partialAmount;

               projTransPostingOrig.Qty =  partialQty;

           }

           projTransPostingOrig.PaymentStatus = _paymentStatus;

           projTransPostingOrig.PaymentDate = _paymentDate;

           projTransPostingOrig.update();

    }

    ttscommit;

    it works with small number of records but it doesn't work for case i have 300 Record it continue to loop for more than 300 and i don't know why exactly this case happened and table have only 300 record

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

    I don't see why that code would be stuck in an infinite loop.

    However please note that in the middle of your while statement you are inserting new records that match your select criteria.

    Still, the actual selection should happen before the iteration of the while loop happens, so it shouldn't have an impact.

    But you could try if it starts working by not inserting the records to the database in the while loop. Instead use a RecordInsertList to insert all new records after the while loop has been completed.

    (msdn.microsoft.com/.../recordinsertlist.aspx)

  • Peter Samir Profile Picture
    446 on at

    Hi,

    Did you find a solution as I have the same issue exactly with the same method while trying to settle a project invoice.

    Actually, I tried to use "RecordInsertList" but unfortunately I still have the same issue.

    Thanks

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Peter,

    Check if ProjTransPosting table has overwritten insert\update\delete methods to update SyncProjTransaction table. If yes, you can try to use doInsert and doUpdate on ProjTransPosting to skip this logic and check if it works faster?

  • Peter Samir Profile Picture
    446 on at

    Hi Sergei,

    All methods are default and there are no overwritten.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans