Import CSV file that has different table structure then the table into CSV is being imported

DamjanDamjan Member Posts: 38
Hi,

I need to import some data saved in CSV file into T81 - Gen. Journal Line
File structure of CSV file is not identical to table structure.

How to import such CSV using XMLPort? Should I import first in Temp Table and then from temporary table to T81?

Thank you
BR Damjan

Best Answer

  • irasoelbaksirasoelbaks Netherlands, theMember Posts: 80
    edited 2021-02-24 Accepted Answer
    To skip the first line in the csv file just set a boolean flag True in the OnInitXMLport() then in the OnBeforeInsertRecord() for example set the boolean flag to false AND perform a currXMLport.SKIP else just process the csv lines.

Answers

  • edoderooedoderoo Member Posts: 86
    Take a look at xml-port 9171, 9172. Altough the fields are here in the order of the table structure, it is not necessary to do so. You can also define variables to fetch the data from the csv, and use the code to fill the table records, and insert (or update) them in code.
    IF User.Loves('Edo') THEN ok() ELSE currReport.genSkip;
  • DamjanDamjan Member Posts: 38
    Hi
    I managed to create XMLPort and at the moment there is also first record inserted into T81 - Gen. Journal Line, but this 1 record is header row in CSV, I need to skip that.

    It inserts all columns from CSV file: "Column A" is inserted in first field element of the table "Gen. Journal Line", "Column B" is inserted in second field element on the table: "Gen. Journal Line", etc.

    How can I skip fields that I do not need to insert -> CurrXML.SKIP -> this skip processing of XMLPort and closes the object, it does not skip the first row (header row).

    And, there is one other thing, although I insert a new record with primary key on "Journal Template Name", "Journal Batch Name", "Line No." I get the error:

    Microsoft Dynamics NAV

    Break On Error Message:

    The Gen. Journal Line already exists. Identification fields and values: Journal Template Name='TEST',Journal Batch Name='DZ',Line No.='10000'
    OK

    Thanks Damjan
  • irasoelbaksirasoelbaks Netherlands, theMember Posts: 80
    edited 2021-02-24 Accepted Answer
    To skip the first line in the csv file just set a boolean flag True in the OnInitXMLport() then in the OnBeforeInsertRecord() for example set the boolean flag to false AND perform a currXMLport.SKIP else just process the csv lines.
  • DamjanDamjan Member Posts: 38
    Hi,
    After CurrXMLPort.SKIP code goes to the OnPostXMLPort() and exits the code, so that XMLPort is closed.

    Code is attched in the printscreen
    nrszxsd0l63o.png

    Thanks
  • irasoelbaksirasoelbaks Netherlands, theMember Posts: 80
    Code seems okay. Did you try to follow the execution of the code with the debugger?
  • DamjanDamjan Member Posts: 38
    Hi,
    I created new object XMLPort with identical code and it works as expected.

    Thank you
    BR Damjan
Sign In or Register to comment.