creating a log file with dataports import

Hallo, I want to import data from a csv file, and track in a logfile the lines that have been imported. So I have some code like this: ---------------- Dataport- OnInitDataport logfile.TEXTMODE(TRUE); bestandnaam:=‘c:\log ‘+ FORMAT(CURRENTDATETIME,13,’<Day,2><Month,2><Year,2> <Hours24,2><Minutes,2><Seconds,2>’)+’.txt’; logfile.CREATE(bestandnaam); Customer-OnAfterImportRecord lineno+=1; VALIDATE(“Country Code”,“TmpCountry Code”); IF INSERT THEN logfile.WRITE('Ingevoegd regel: '+FORMAT(lineno)) ELSE IF MODIFY THEN logfile.WRITE('Gewijzigd regel: '+FORMAT(lineno)) ELSE logfile.WRITE('ERROR in regel: '+FORMAT(lineno)); Dataport-OnPostDataport logfile.CLOSE; -------------- The problem is now that when the validate fails, the program deletes the logfile. Is there a way to avoid this?

Hello Jan, maybe the simplest way would be to make the validations “yourself”. I mean, copy the code in the “Country Code”.OnValidate trigger, and handle errors in your dataport code. Seasonal greetings to you and all others on mbsonline! Pelle

In theory you can CLOSE and OPEN (with SEEK for EndOfFile) the file every time you want to write to it (OnInitDataport, OnAfterImportDataport).

Thanks, it works. I think it will not be very fast, but in this case it is only used to convert some data of an old database. I have now something like this: ---------------- Dataport- OnInitDataport logfile.TEXTMODE(TRUE); bestandnaam:=‘c:\log ‘+ FORMAT(CURRENTDATETIME,13,’<Day,2><Month,2><Year,2> <Hours24,2><Minutes,2><Seconds,2>’)+’.txt’; logfile.CREATE(bestandnaam); Customer-OnBeforeImportRecord logfile.OPEN(bestandnaam); logfile.SEEK(curpos); Customer-OnAfterImportRecord lineno+=1; VALIDATE(“Country Code”,“TmpCountry Code”); IF INSERT THEN logfile.WRITE('Ingevoegd regel: '+FORMAT(lineno)) ELSE IF MODIFY THEN logfile.WRITE('Gewijzigd regel: '+FORMAT(lineno)) ELSE logfile.WRITE('ERROR in regel: '+FORMAT(lineno)); curpos := logfile.POS; logfile.CLOSE; --------------

Just a note - you can replace curpos := logfile.POS; ... logfile.SEEK(curpos); with logfile.SEEK(logfile.LEN);

Maybe, but I found on this forum that LEN works only with 2048 Bytes. See this topic. All Forums Navision (aka Financials / Attain) Navision (Attain/Financials) - Developer Forum How obtain LEN of unsaved file ?