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...
Suggested answer

Excel import not work well

(0) ShareShare
ReportReport
Posted on by 119

Hello,
I tried to import data from excel file. And I created Report for import. 
The primary thing is to import data into "Item Import Line" table (created by developers from another company) and after that with another function to import data into Item and some other tables. 
The problem is in the Import  data from excel. 
When I run report, first thing is Open Choose File Dialog, and after I choose I got following message:
" The Item Import Line Does not exist. Identification fields and values: Document No.="docNo";Jumbo Code='jmboCode'; Barcode='1254787788887'; Store Code='' "

Primary key of "Item Import Line" table is that 4 fields, and "Jumbo Code" field is key for own.
If Jumbo Code does not exist into table I can't import, but if exist I can.
The point is that I 'must' import records whatever "Jumbo Code" exists or not. 
This is my import function.

ExcelBuf.SETCURRENTKEY("Row No.","Column No.");
ExcelBuf.SETRANGE("Row No.",1);
ExclBufferFirstRow.COPY(ExcelBuf);
ExcelBuf.SETFILTER("Row No.",'>1');
RowNo := 0;
IF ExcelBuf.FINDSET THEN BEGIN
  REPEAT
    IF RowNo <> ExcelBuf."Row No." THEN BEGIN
      IF ExclBufferFirstRow.FINDSET THEN BEGIN
        REPEAT
              IF ExcelBuf.GET(ExcelBuf."Row No.",ExclBufferFirstRow."Column No.") THEN BEGIN
                    CASE ExclBufferFirstRow."Cell Value as Text" OF
                      JumboCode:
                        BEGIN
                          ItemImportLine.INIT;                          
                          ItemImportLine."Jumbo Code" := ItemImportLine."Jumbo Code";
                          ItemImportLine."Document No." := ItemImportHeader."No.";
                          ItemImportLine."Jumbo Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.INSERT;
                          END;
                      Barcode:
                        BEGIN
                          //ItemImportLine.INIT;
                          //ItemImportLine."Document No." := ItemImportHeader."No.";
                          ItemImportLine.Barcode := ExcelBuf."Cell Value as Text";                         
                          ItemImportLine.MODIFY;
                          END;
                      ItemDescription:
                        BEGIN
                          ItemImportLine."Item Description" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      SuppliersCode:
                        BEGIN
                          ItemImportLine."Suppliers Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      RetailPrice:
                        IF EVALUATE(ItemImportLine."Retail Price",ExcelBuf."Cell Value as Text") THEN
                          ItemImportLine.MODIFY;
                      BaseUnitofMeasure:
                            BEGIN
                          ItemImportLine."Base Unit of Measure" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      Type:
                        BEGIN
                          ItemImportLine.Type := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      TypeDescription:
                        BEGIN
                          ItemImportLine."Type Description" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemCategoryCode:
                        BEGIN
                          ItemImportLine."Item Category Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemCategoryDescription:
                        BEGIN
                          ItemImportLine."Item Category Description" := ExcelBuf."Cell Value as Text";
                         // ItemImportLine.MODIFY;
                        END;
                      ItemMainGroupCode:
                        BEGIN
                          ItemImportLine."Item Main Group Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemMainGroupDescription:
                        BEGIN
                          ItemImportLine."Item Main Group Description" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemSubGroupCode:
                        BEGIN
                          ItemImportLine."Item Sub Group Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemSubGroupDescription:
                        BEGIN
                          ItemImportLine."Item Sub Group Description" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      WayofStorageCode:
                        BEGIN
                          ItemImportLine."Way of Storage Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      Quantity:
                        IF EVALUATE(ItemImportLine.Quantity,ExcelBuf."Cell Value as Text") THEN
                         ItemImportLine.MODIFY;
                      InPackage:
                        BEGIN
                          ItemImportLine."In Package" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      OutPackage:
                        BEGIN
                          ItemImportLine."Out Package" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      PackageofShipment:
                        BEGIN
                          ItemImportLine."Package of Shipment" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemSeasonCode:
                        BEGIN
                          ItemImportLine."Item Season Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemSeasonDescription:
                        BEGIN
                          ItemImportLine."Item Season Description" := ExcelBuf."Cell Value as Text";
                        //  ItemImportLine.MODIFY;
                        END;
                      PriorityofCategory:
                        BEGIN
                          ItemImportLine."Priority of Category" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      PriorityofMainGroup:
                        BEGIN
                          ItemImportLine."Priority of Main Group" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      PriorityofSubGroup:
                        BEGIN
                          ItemImportLine."Priority of Sub Group" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      PeakofPeriodCode:
                        BEGIN
                          ItemImportLine."Peak of Period Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      PeakofPeriodDescription:
                        BEGIN
                          ItemImportLine."Peak of Period Description" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      Flag:
                        IF EVALUATE(ItemImportLine.Flag,ExcelBuf."Cell Value as Text") THEN
                          ItemImportLine.MODIFY;
                      Weight:
                         IF EVALUATE(ItemImportLine.Weight,ExcelBuf."Cell Value as Text") THEN
                          ItemImportLine.MODIFY;
                      Volume:
                        BEGIN
                          ItemImportLine.Volume := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      CountryofOrigin:
                        BEGIN
                          ItemImportLine."Country of Origin" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      BuyerCode:
                        BEGIN
                          ItemImportLine."Buyer Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      BuyerName:
                        BEGIN
                          ItemImportLine."Buyer Name" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      VendorCode:
                        BEGIN
                          ItemImportLine."Vendor Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      VendorName:
                        BEGIN
                          ItemImportLine."Vendor Name" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.MODIFY;
                        END;
                      ItemAL:
                        BEGIN
                         IF ExcelBuf."Cell Value as Text" = 'Yes' THEN
                          ItemImportLine."Item AL" := TRUE
                          ELSE
                          ItemImportLine."Item AL" := FALSE;
                          ItemImportLine.MODIFY;
                        END;
                      StoreCode:
                        BEGIN
                          ItemImportLine."Store Code" := ExcelBuf."Cell Value as Text";
                          ItemImportLine.INSERT;
                        END;
                      //LocationCode:
                        //BEGIN
                          //ItemImportLine."Location Code" := ExcelBuf."Cell Value as Text";
                          //ItemImportLine.MODIFY;
                        //END;
                      //MaterialCode:
                        //BEGIN
                          //ItemImportLine."Material Code" := ExcelBuf."Cell Value as Text";
                          //ItemImportLine.MODIFY;
                        //END;
                      //VATBusinessPostingGroup:
                        //BEGIN
                          //ItemImportLine."VAT Business Posting Group" := ExcelBuf."Cell Value as Text";
                          //ItemImportLine.MODIFY;
                        //END;
                END;
              END;
        UNTIL ExclBufferFirstRow.NEXT = 0;
      END;
      RowNo := ExcelBuf."Row No.";
    END;
  UNTIL ExcelBuf.NEXT = 0;
END;


  • Suggested answer
    Journey22 Profile Picture
    5 on at
    RE: Excel import not work well

    You INSERT then assign a value to Barcode and MODIFY

    If Barcode is part of the Primary Key, you cannot MODIFY a Primary Key field

    Take out all of the INSERT and MODIFY statements and just add the INSERT statement at the end of the REPEAT processing for each Excel row

    Also a handy tip use the debugger to find out where in the code an error is being generated from

    Hope this helps!

  • Suggested answer
    THE Italian Profile Picture
    on at
    RE: Excel import not work well

    This is customized code. You have to refer to the one whom generated that code or customized it. 

    If you have none helping you with that, you might look in the market for a free lance to review the code implementation. 

    Last, but not least, NAV 2009 is completely out of support since few years now. I would better discuss with partner/customer to upgrade as soon as possible to 

    a. come back being fully supported by Microsoft

    b. leverage the latest and greatest MS technologies

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 446 Super User 2025 Season 1

#2
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 343

#3
Mansi Soni Profile Picture

Mansi Soni 327

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans