Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()

(0) ShareShare
ReportReport
Posted on by 1,550
Hi,

If i've insterted data to a tmpDB table using recordInsertList, how can i loop through the table and get the records inside it

RecordInsertList    tmpDBTableRecordInsertList = new RecordInsertList(tableNum(TmpDBTable));
 
while //logic
{
TmpDBTable tmpDBTable;
tmpDBTable.Field1 = Table1.Field1
tmpDBTable.Field2 = Table1.Field2
 
tmpDBTableRecordInsertList.Add(tmpDBTable);
}
tmpDBTableRecordInsertList.InsertDatabase();

how can i now while loop through all the values that i inserted to the tmp table?
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()
    It seems you missed first two sentences of my previous reply.
     
    You must use the table buffer (tmpDBTable) as the seventh parameter of RecordInsertList's constructor. That's what defines to which buffer the records will be inserted to. It also means that you must declare the table buffer before creating the insert list.
  • junior AX Profile Picture
    junior AX 1,550 on at
    How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()
    Hi Martin and Girish,

    Apologies this is a typo, the original code definitely inserts to the database with the recordInsertList buffer, just like the original question shows.
    I removed the clear but still same issue, the while loop for the tmpDB is empty
     
    internal final class RunnableClass1
    {
        /// <summary>
        /// Class entry point. The system will call this method when a designated menu 
        /// is selected or when execution starts and this class is set as the startup class.
        /// </summary>
        /// <param name = "_args">The specified arguments.</param>
        public static void main(Args _args)
        {
            RecordInsertList    tmpDBTableRecordInsertList = new RecordInsertList(tableNum(TmpDBTable));
    
            ttsbegin;
            TmpDBTable tmpDBTable;
            tmpDBTable.Field1 = 2;
            tmpDBTable.Field2 = 2;
    
            tmpDBTableRecordInsertList.add(tmpDBTable);
    
            //tmpDBTable.clear();
            tmpDBTable.Field1 = 1;
            tmpDBTable.Field2 = 1;
    
            tmpDBTableRecordInsertList.add(tmpDBTable);
    
            tmpDBTableRecordInsertList.insertDatabase();
            ttscommit;
    
            while select tmpDBTable
            {
                Info(int642Str(tmpDBTable.Field1));
            }
        }
    
    }
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()
    Your code is incorrect - if you want to use RecordInsertList with a temporary table, you must specify the temporary table buffer (to insert records to) in the seventh argument of RecordInsertList().
     
    You can simply query this table buffer after RecordInsertList added records there.
     
    You're declaring a new temporary buffer inside the loop, each of them will almost immediately cease to exist. Both is wrong. You want to insert all records to single buffer and you don't want to immediately throw it away, otherwise there would be no point in insert records to it.
  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()
    Hi JuniorAX,
     
    Your code is wrong, and it must throw compilation errors. You are calling insertDatabase using the table buffer. It must be buffer for RecordInsertList.
    Also please remove the tempDBTable.clear() line from your code.
    Also, in explanation to the original post - There is no method available to loop through records from RecordInsertList - I would suggest you to create new list type variable and insert the values to the list inside the while select statement. Later you can use ListEnumerator to loop through the records.
     
    Thanks,
    Girish S.
  • junior AX Profile Picture
    junior AX 1,550 on at
    How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()
    Hi Andre,

    i did this quickly in a runnable class but it didn't work, the code didn't get inside the while loop for the tmp table -- what am i missing? what did you mean by "the loop should be done in the same logic"?
    internal final class RunnableClass1
    {
        /// <summary>
        /// Class entry point. The system will call this method when a designated menu 
        /// is selected or when execution starts and this class is set as the startup class.
        /// </summary>
        /// <param name = "_args">The specified arguments.</param>
        public static void main(Args _args)
        {
            RecordInsertList    tmpDBTableRecordInsertList = new RecordInsertList(tableNum(TmpDBTable));
    
            ttsbegin;
            TmpDBTable tmpDBTable;
            tmpDBTable.Field1 = 2;
            tmpDBTable.Field2 = 2;
    
            tmpDBTableRecordInsertList.add(tmpDBTable);
    
            tmpDBTable.clear();
            tmpDBTable.Field1 = 1;
            tmpDBTable.Field2 = 1;
    
            tmpDBTableRecordInsertList.add(tmpDBTable);
    
            tmpDBTable.insertDatabase();
            ttscommit;
    
            while select tmpDBTable
            {
                Info(int642Str(tmpDBTable.Field1));
            }
        }
    
    }
     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,162 Super User 2025 Season 1 on at
    How to get data from a tmp table, that was inserted via RecordInsertList.InsertDatabase()
    Hi Junior AX,
     
    I would suggest using ttsbegin and ttscommit to define a transaction scope. Then you can use the while select statement to loop the records. Note that the loop should be done in the same logic. If you have one process creating records in the temporary table and another process to loop them, then the table is empty. 

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans