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 :
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,247

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;

I have the same question (0)
  • Samantha73 Profile Picture
    3,247 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
    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

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,151

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,443 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,092 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans