XMLPort(Import) Skip the first line, AutoIncrement Property

mustafaAlsoufimustafaAlsoufi Member Posts: 65
edited 2020-10-08 in NAV Three Tier
Hello experts,

I'm trying to import a CSV file using XMLPort, please find the screenshot below on how my table looks like
1zl2we7erlby.png
The Entry No. is the PK
That's being said, I have a couple of questions regarding XMLPort(Import).
1) While importing I'm getting the following error unless I change the 'AutoIncrement' Property for the 'Entry No.' to yes then the problem would be solved but caused another issue which is the 'Entry No.' will keep being incremented after another import even if I deleted some/all of the fields in the table
zbchb809iybg.png
performance-wise, should I keep the AutoIncrement Property Yes or No, and how could I fix the issue of resetting the Entry No. to be matched with the previous Entry No.

2) My second question, is there a way to ignore the first line in the CSV file IF there is a header in that file, if not import everything. If so, could anyone share the code with me, please?

Thanks in advance.

Answers

  • AlexeyShaminAlexeyShamin Member Posts: 80
    edited 2020-10-08
    Hello! Do you import Entry No from file?
    If no - Set field "Entry No." in trigger OnBeforeInsertRecord in XMLPort

    Example
    Table1 - Import::OnBeforeInsertRecord
    Table1."Entry No." := I;
    I += 1;

    To skip line use
    currXMLPort.SKIP when you read first line
  • mustafaAlsoufimustafaAlsoufi Member Posts: 65
    No I'm not importing the "Entry No." from a file.

    On the other hand, I tried to add the code you suggested but unfortunately I'm still getting the same error. For some reason it seems that the Entry No. is not being incremented everytime a line being imported
  • AlexeyShaminAlexeyShamin Member Posts: 80
    I think you have record in testtable with "entry no." = 0.
    In init xml port trigger try to initialize "i" variable as:
    Testtable.RESET;
    I:=1;
    IF Testtable.Findlast then
    I:= testtable."Entry No.";
Sign In or Register to comment.