web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Insertion of multiple records

(0) ShareShare
ReportReport
Posted on by

Hi all,

I am new to AX. I am creating a table and inserting a record in the required fields in the table via the Runnable class(job). So, what should i do if i ant  to insert multiple records in the SAME table in the Runnable class itself. I studies about the inset_recordset  but i don't know, i am thinking that its for inserting records into a table picking from another table. If i am wrong, then please correct me and kindly help me in the code to insert multiple records in the same table.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    You can use the while select if you need to add logic in the fields, the while will call the table in SQL as many times the while is running, but If you use the insert_recordset will only call once the table in SQL and that is why this is a good bestpractices that Microsoft recommend when you want to insert multiple records.

  • Community Member Profile Picture
    on at

    Here's my code:

    I wrote this Just have a look and tell me where are the errors. Its not running.

    class InsertionClass

    {      

       /// <param name = "_args">The specified arguments.</param>

       public static void main(Args _args)

       {  

           PTable ptb;

           ttsbegin;

           while select forupdate ptb where

           ptb.P_ID = "P101";

           ptb.Pricee = 47;

           ptb.PStatus = "Approved";

           ptb.insert();

           ptb.P_ID = "P102";

           ptb.Pricee = 86;

           ptb.PStatus = "Confirmed";

           ptb.insert();

           ptb.P_ID = "P103";

           ptb.Pricee = 109;

           ptb.PStatus = "Invoiced";

           ptb.insert();

           ttscommit;

       }

    }

  • Suggested answer
    Martin Dráb Profile Picture
    239,257 Most Valuable Professional on at

    Whether you can use insert_recordlist depends on how you can define values for the records. It's possible that you can't use it in your case.

    But there is still is a better approach than inserting records one by one: RecordInsertList.

  • Martin Dráb Profile Picture
    239,257 Most Valuable Professional on at

    Your code looks very strange; I think it shouldn't even compile (because of the assignment in where ptb.P_ID = "P101").

    What are you trying to achieve by using a while select? You said you wanted to insert records, you didn't mention any selects.

  • Suggested answer
    Community Member Profile Picture
    on at

    Mansi Tripathy,

    When you insert record in table, it creates connection with db, inserts data and then closes the connection.

    insert_recordset doesn't do it for every record, rather it keeps the data in recrodset and then goes to db only once and dump all the data.

    So, If you are to insert the records in bulk you should definitely use insert_recordset. It is about round trip to db that is minimal in insert_recordset approach.

  • Community Member Profile Picture
    on at

    Yes, its showing the error of that assignment. I am not sure how to insert multiple records.  How can i use insert_recordset to insert in the same table without getting the values from another table?

    Can us how me the demonstration of any 2 records insertion. Kindly help.

  • Community Member Profile Picture
    on at

    I am getting confused while studying about the insert_recordset online as everywhere they are using 2 tables.

  • Verified answer
    Martin Dráb Profile Picture
    239,257 Most Valuable Professional on at

    Well, you must fix compilation errors before you can at least run your code.

    Because you didn't explain the purpose of the while select, I'll assume using it was just a mistake on your side and I'll ignore it completely.

    To insert a record, simply set field values you want and call insert(). To create several records, repeat the procedure several times.

    PTable ptb;
    
    ptb.P_ID = "P101";
    ptb.Pricee = 47;
    ptb.PStatus = "Approved";
    ptb.insert();
    
    ptb.P_ID = "P102";
    ptb.Pricee = 86;
    ptb.PStatus = "Confirmed";
    ptb.insert();
    
    ptb.P_ID = "P103";
    ptb.Pricee = 109;
    ptb.PStatus = "Invoiced";
    ptb.insert();

    Note that you usually should check if the record can be inserted (by calling validateWrite() and reacting accordingly if it returns false).

  • Martin Dráb Profile Picture
    239,257 Most Valuable Professional on at

    Hi Mansi, I moved your question about updates to a separate thread; it didn't belong to the thread named "Insertion of multiple records".

    Also, you confirmed that your question had been answered, but you forgot to mark the verified answer (Did this answer your question? > Yes). Let me do it for you this time, but please do it by yourself in future.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 4 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans