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 :
Small and medium business | Business Central, N...
Answered

Excel buffer import - Insert Line number from code For Loop

(0) ShareShare
ReportReport
Posted on by 3,390

Hi All

I'm trying to  import sales invoices from excel buffer to a staging table and  set the line number similar to sales line table.  However my code doesn't work and couldn't figure out the for loop and assigning a line number (line number should increase with each record from Excel buffer to staging table)

Here's the code

                        for row := 1 to LastRow do begin

                            NextLineNo := 1000;//

                            //Clear(Data);

                            Staging.Init();

                            Staging.U_No := ImportHeader.U_No;

                            Staging.U_DocumentType := Staging.U_DocumentType::Invoice;

                            nextLineNo := nextLineNo + 10000;//

                            Staging.U_LineNo := nextLineNo;//

                            Staging.U_DocKey := Buffer.GetText(Buffer, 'P', row);

                            Staging.U_BillToCustomerNo := Buffer.GetText(Buffer, 'J', row);

                            Staging.U_Type := Staging.U_Type::Item;

                            Staging.U_ItemNo := Buffer.GetText(Buffer, 'K', row);

                            Staging.Insert(true);

                        end;

  • Samantha73 Profile Picture
    3,390 on at

    This is solved by inserting the first assignment of line no before the loop (NextLineNo := 1000;)..silly mistake

  • Verified answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    Thank you for sharing final solution. This helps others.

    Thanks.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 753 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 583 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 302 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans