Options

SAVEASPDF Function

jflynnjflynn Member Posts: 34
edited 2011-07-16 in NAV Three Tier
I am trying to save PDF's to a directory before I email them. The code is in a codeunit called from a Page. Multiple PDF's get created in the directory with the Invoice Number in the Name. The issue is that when I open the PDF's they are all for the same invoice (SPI000000).

SalesInvHeader.RESET;
SalesInvHeader.SETRANGE(SalesInvHeader."Bill-to Customer No.",'549200');
IF SalesInvHeader.FINDSET THEN
REPEAT
Name := STRSUBSTNO('SalesInvoice_%1.pdf', SalesInvHeader."No.");
ToFile := '\\pegasus\ftproot$\Invoices\' + Name; // cifs delegation to service tier for pegasus
CLEAR(SalesInvHeader2);
SalesInvHeader2.GET(SalesInvHeader."No.");
REPORT.SAVEASPDF(REPORT::"WL Sales Invoice",ToFile,SalesInvHeader2);
UNTIL SalesInvHeader.NEXT = 0;


Directory of \\pegasus\ftproot$\Invoices after the code runs. Even though the file names are different, the pdf always contains the first invoice. I also tried running the report from a variable that I cleared first. This gave the same results.
I also tried the download function.

07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000000.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000001.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000002.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000003.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000004.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000006.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000007.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000012.pdf
07/15/2011 03:50 PM 1,200,495 SalesInvoice_SPI000016.pdf
07/15/2011 03:51 PM 1,200,495 SalesInvoice_SPI000017.pdf
07/15/2011 03:51 PM 1,200,495 SalesInvoice_SPI000018.pdf

Any help would be appreciated.

Thanks
Joe

Answers

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    try with

    SalesInvHeader.RESET;
    SalesInvHeader.SETRANGE(SalesInvHeader."Bill-to Customer No.",'549200');
    IF SalesInvHeader.FINDSET THEN
    REPEAT
    Name := STRSUBSTNO('SalesInvoice_%1.pdf', SalesInvHeader."No.");
    ToFile := '\\pegasus\ftproot$\Invoices\' + Name; // cifs delegation to service tier for pegasus
    SalesInvHeader2.RESET;
    SalesInvHeader2.SETRANGE("No.",SalesInvHeader."No.");
    IF SalesInvHeader2.FINDFIRST THEN
      REPORT.SAVEASPDF(REPORT::"WL Sales Invoice",ToFile,SalesInvHeader2);
    UNTIL SalesInvHeader.NEXT = 0;
    
  • Options
    kinekine Member Posts: 12,562
    SalesInvHeader2.RESET;
    SalesInvHeader2.SETRANGE("No.",SalesInvHeader."No.");
    IF SalesInvHeader2.FINDFIRST THEN
      REPORT.SAVEASPDF(REPORT::"WL Sales Invoice",ToFile,SalesInvHeader2);
    

    You do not need to get the record (use the FINDFIRST). Only filters are passed to the report and you know that the record exists, you do not need to get it...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    jflynnjflynn Member Posts: 34
    Kamil and Mohana,

    Thank you for the solution. It works perfectly now. Appreciate the quick response.

    Joe
    Joe
Sign In or Register to comment.