Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Xmlport - How to skip first line of CSV import-file

Posted on by 670

I have a basic XMLPort to import a CSV file into the General Journal Line (81) BC table. This is working fine if I manually remove the header line at the top of the file.

I've seen various web-pages that say you can do something like the code below to skip the first line of the import-file. However, it still evaluates the data in the line instead of ignoring/skipping the line. It's reporting: "The length of the string is 21, but it must be less than or equal to 10 characters. Value: Journal Template Name".

1. Declare a global Boolean var (e.g.)
   var
          bFirstLine: Boolean;

2. trigger OnPreXmlPort()
    begin
       bFirstLine := true;
    end;

3. 

trigger OnBeforeInsertRecord()
var
begin
   if bFirstLine then begin
      bFirstLine := false;
      currXMLport.Skip();
   end;
end;

Am I using the wrong event perhaps? Any help would be greatly appreciated. Here's a sample of the data:-

"Journal Template Name","Journal Batch Name","Line No.","Account Type","Account No.","Posting Date","Document Type","Document No.","Description","Currency Code","Amount","Amount (LCY)","Shortcut Dimension 1 Code","Shortcut Dimension 2 Code"
"GENERAL","OPEN","6","G/L Account","TLPUK0099","01/01/2018","","00000400001","","EUR","100.000","95.460","",""
"GENERAL","OPEN","10","G/L Account","TLPUK0099","31/01/2018","","00000700001","Revalued Source","EUR","1","-5.370","",""
"GENERAL","OPEN","11","G/L Account","TLPUK0099","01/02/2018","","00000700002","Revalued Source REVERSING ENTRY","EUR","1","5.370","",""
"GENERAL","OPEN","14","G/L Account","TLPUK0099","28/02/2018","","00000800001","Revalued Source","EUR","1","-8.500","",""
"GENERAL","OPEN","15","G/L Account","TLPUK0099","01/03/2018","","00000800002","Revalued Source REVERSING ENTRY","EUR","1","8.500","",""

  • Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: Xmlport - How to skip first line of CSV import-file

    Please verify the solution if it worked, so others can benefit from this thread..

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Xmlport - How to skip first line of CSV import-file

    Great.

  • Nick Webb Profile Picture
    Nick Webb 670 on at
    RE: Xmlport - How to skip first line of CSV import-file

    Wow! That was quick. All fixed. Many thanks for your prompt response.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Xmlport - How to skip first line of CSV import-file

    Hi,

    Can you try this?

       trigger OnInitXmlPort()

       begin

           firstrow := true;

       end;

    trigger OnAfterInitRecord()

                   begin

                       if firstrow then begin

                           firstrow := false;

                           currXMLport.Skip();

                       end;

                   end;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans