Export to CSV via report (NAV2015)

bRahms
edited 2016-02-09 in NAV Three Tier
Hi,
My client doesn't have Xmlports in their licence, thus wants to export data in a CSV via Reports.
Can we create a report on the server, ProcessingOnly, that exports data without getting the error that the file is already open?
OnPreDataItem=BEGIN
                               tpath := 'C:\Users\User\Documents\';
                               tFilename := tpath + 'listing-'+ FORMAT(TODAY,0,'<day,2>-<month,2>-<year,2>')+
                                           FORMAT(TIME, 0, '<hour,2><minute,2><second,2>')
                                           +'.' + 'csv';

                               CLEAR(fFileToExport);
                               CLEAR(objFileSystem);
                               CREATE(objFileSystem, TRUE, TRUE);
                               IF NOT objFileSystem.FileExists(tFilename) THEN
                                  fFileToExport.CREATE(tFilename)
                               ELSE BEGIN
                                  fFileToExport.TEXTMODE(TRUE);
                                  fFileToExport.OPEN(tFilename);
                               END;
                               CLEAR(objFileSystem);


                               fFileToExport.TEXTMODE(TRUE);
                               fFileToExport.WRITEMODE(TRUE);


                               fFileToExport.WRITE(';;"Test Column 3"');
                             END;

               OnAfterGetRecord=BEGIN
                                  fFileToExport.WRITEMODE(TRUE);
                                  fFileToExport.TEXTMODE(TRUE);
                                  fFileToExport.WRITE('test 2');
                                END;

               OnPostDataItem=BEGIN
                                CLEAR(fFileToExport);
                                
                              END;
                               }
Thanks in advance for your help

Best Answer

Answers

  • you can check if the file exists - if that is what you mean
  • When running the above code (on server level), he gives the error that the action cannot be performed when the file is open.
  • Is the DataItem this code is in the root DataItem? It must be.

    If your file isn't open in another application check whether your OPEN gets called muliple times for some reason.
    If that doesn't happen restart the service on your DEV Machine. Had that happen multiple times that NAV leaves files open for an eternity if you don't close them properly.

    Austrian NAV/BC Dev
  • Even a restart of the service gave me the same error.
    The code is in the root dataitem.
  • Correct :)

    + the fact that i didn't have to use the writemode function any longer.

    Thanks for the help all.