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 :
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!

I have the same question (0)
  • Suggested answer
    Deepak Agarwal Profile Picture
    8,602 on at

    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.

  • Suggested answer
    Martin Dráb Profile Picture
    237,948 Most Valuable Professional on at

    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
    Suresh M. Parmar Profile Picture
    340 on at

    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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans