Options

In NAV 2016, how can I get the XMLport to save a file without any interaction from the user?

vimovimo Member Posts: 14
Hello!
I have an XMLport that exports a report to a CSV file. No issues there. When the XMLport runs, I would like the file to be saved to the export folder without the Export File Dialog box opening and asking: “Do you want to open or save this file?” See Image1. There is a checkbox that I can uncheck “Always ask before opening this type of file.” But when I uncheck it,the Export dialog box still opens up, see Image2, with the correct export folder automatically selected, but I still need to click the Save button.
How can I get the XMLport to Save a file without any interaction from the user? Image3 shows the properties of the XMLport.
Thanks!

Best Answer

  • Options
    ftorneroftornero Member Posts: 522
    Answer ✓
    You can create a report without any DataItem , with the propierties UseRequestPage = No and ProcessingOnly = Yes

    And put thos code in the
    OnPreReport()
    // FileMgt codeunit 419
    // FileName Text
    // OutFile File
    // OutS OutStream
    // Xmlp your XMLPort

    FileName := FileMgt.ServerTempFileName('CSV');
    OutFile.CREATE(FileName);
    OutFile.CREATEOUTSTREAM(OutS);
    Xmlp.FILENAME(FileName);
    Xmlp.SETDESTINATION(OutS);
    Xmlp.EXPORT;
    OutFile.CLOSE;
    FileMgt.DownloadToFile(FileName, 'c:\output\ExportFile.csv');

    And execute the report.

    You can create a codeunit too with the same code if you like it more.

    Regards.

Answers

Sign In or Register to comment.