Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

While looping a temp table and after the loop, the records are disappeared from the temp table - need help

(0) ShareShare
ReportReport
Posted on by 10

Hello,

    I have a temp table that has a record for now (it may have more in different scenarios). I am doing a while loop on it to fill another temp table and here is the code looks like

while select tmpProjAdjustmentSale
            where tmpProjAdjustmentSale.TransId == tmpProjAdjustment.TransId
        {
            tmpProjAdjustmentCreateSale.clear();
            tmpProjAdjustmentCreateSale.RefRecId        = tmpProjAdjustmentCreate.RecId;
            tmpProjAdjustmentCreateSale.SaleRefRecId    = tmpProjAdjustmentSale.SaleRefRecId;
            tmpProjAdjustmentCreateSale.FundingSource   = tmpProjAdjustmentSale.FundingSource;
            tmpProjAdjustmentCreateSale.SalesPrice      = tmpProjAdjustmentSale.SalesPrice;
            tmpProjAdjustmentCreateSale.LineAmount      = -tmpProjAdjustmentSale.LineAmount;
            if (tmpProjAdjustment.AdjustmentType == ProjAdjustmentType::Revenue)
            {
                tmpProjAdjustmentCreateSale.SalesPrice  = -tmpProjAdjustmentSale.SalesPrice;
                tmpProjAdjustmentCreateSale.LineAmount  = -tmpProjAdjustmentSale.LineAmount;
            }
            tmpProjAdjustmentCreateSale.DefaultDimension = tmpProjAdjustmentSale.DefaultDimension;
            tmpProjAdjustmentCreateSale.insert();
            //select * from tmpProjAdjustmentSale;
            
        }

I am not sure if I am missing something here but when it finishes the loop then when I mouse hover or add the temp table to the watch window there is no record the record in the tmpProjAdjustmentSale disappears. tmpProjAdjustmentSale is a class level variable. Anything wrong in the code?

AX version: AX 2012 feature pack

Thanks!

  • Suggested answer
    Suresh M. Parmar Profile Picture
    Suresh M. Parmar 340 on at
    RE: While looping a temp table and after the loop, the records are disappeared from the temp table - need help

    Hi,

    While select method will fetch the data until the record getting null(i.e, will execute up to satisfy the condition) after last iteration record will get blank, if you are going to check the record at last, it will display 0 RecId(a blank record).

    docs.microsoft.com/.../while-select-statements

    If you want the table records again then you need to write another while select for tmpProjAdjustmentSale

    NOTE: For best practice use the same while select and execute your logic.

    Thanks,

    Suresh Parmar

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 231,430 Most Valuable Professional on at
    RE: While looping a temp table and after the loop, the records are disappeared from the temp table - need help

    Nothing is wrong with the code, just with the way how you check if the variable points to a data set with records.

    What you see in the variable is just a single record; which one it depends on what you've assinged there. Because you iterated the table to the point that there are no records remaining, the currently loaded record is none.

    Use a select statement to fetch data from the temporary table.

  • Suggested answer
    Deepak Agarwal Profile Picture
    Deepak Agarwal 8,566 on at
    RE: While looping a temp table and after the loop, the records are disappeared from the temp table - need help

    Hi,

    Pl try below

    1. Use another while loop and use the info to show values stored in tmp table.

    2. Double check the table type (Ideally both temp DB and Immomery should work here)

    3. Call validateWrite before insert, there could be something that stopping to insert data in the 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans