Search code examples
dynamics-nav-2013dynamics-nav-2016dynamics-nav-2015

Save every record in the table as PDF


The have a two records in a table called Bill Info, I have designed a report to the table and need to save each record into pdf file in a specific folder.

CustBill.RESET;
CustBill.SETFILTER(CustBill."Customer No.",'%1',Customers."No.");
IF CustBill.FIND('-') THEN 

 Customers.GET(Customers."No.");
 IF Customers.FIND('-')THEN BEGIN

   REPEAT
  CustNumber:= Customers."No.";
  tofile := '.pdf';
  Filename := 'C:\reports\'+CustNumber+tofile;
  REPORT.SAVEASPDF(50050, Filename,Runrpt);
   UNTIL CustBill.NEXT=0;
END;

Solution

  • Your code is a mess. Here I fixed it for you.

    CustBill.RESET;
    CustBill.SETFILTER(CustBill."Customer No.",'%1',Customers."No.");
    IF CustBill.FIND('-') THEN 
     BEGIN //you missed this one
      CustLocal.SETRANGE("No.", Customers."No.");
      IF CustLocal.FINDSET THEN //use findset already its year 2016
       BEGIN
        REPEAT
         CustNumber:= CustLocal."No.";
         tofile := '.pdf';
         Filename := 'C:\reports\'+CustNumber+tofile;
         REPORT.SAVEASPDF(50050, Filename, CustLocal); //propper parameters
        UNTIL CustBill.NEXT=0;
       end;
     END;
    

    Pay attention to this line

    REPORT.SAVEASPDF(50050, Filename, CustLocal);
    

    Depending on dataitems in report you may have to use CustLocal or CustBill variable as last parameter. It will be used as filterset for your report.

    And one more thing. As MSDN says:

    The FileName parameter specifies a location on the computer running Microsoft Dynamics NAV Server. If you call this function from the RoleTailored client, such as from an action on a page, then use the DOWNLOAD Function (File) to download the .pdf file from the computer running Microsoft Dynamics NAV Server to the computer running the RoleTailored client.

    So don't look for your file on local machine where client is running.

    Any other problems urged you to post the question twice?