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 :
Business Central forum

When i try to create multiple records using a loop this message shows up at second iteration "The record in table already exists" in AL

(0) ShareShare
ReportReport
Posted on by 75

I have a table and i am trying to create multiple records using a Loop, At first iteration record gets inserted but at second iteration its shows that "already exists" when inserted

pastedimage1566818609776v2.png.

i have tried to clear marks of the object so that when new record will be inserted again its gets its new ID. But it's not happening its always assigning the last record's id to new record , maybe that's why this error is showing.
pastedimage1566818683539v3.png

I've also assigned true to the property "AutoIncrement" of my table
pastedimage1566818812585v4.png

Please can anyone help me out to solve this issue , that how will i create multiple records in a loop.

Categories:
  • Verified answer
    Muhammad Arif Maseed Profile Picture
    795 on at

    Write the following code before Order.Init();

    If Order.FindLast then

    Order.ID := Order.ID + 1;

    Hope this code work for you.

  • Verified answer
    Peter Zentner Profile Picture
    390 on at

    You cloud also use an "Clear(orders)" in your loop. This will reset everything to "blank values". If you are doing an Init(), it does not reset the primary key, so when you are doing an insert, the "ID" is already filled out and AutoIncrement doesn't do anything.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans