Invoice by Mail from N4

RainerRainer Member Posts: 103
On Codeunit 82, I call another Codeunit with this code. The problem is that, it is the next-latest invoice which is attatched the mail.

This is only test, a real solution needs more code. BUT all is working exept the "attatch-problem".

..:

OnRun(VAR Rec : Record "Sales Invoice Header")

// Print to PDF file and generate the right invoice !!
REPORT.RUN(50206,FALSE,FALSE,Rec);
AttatchedFileName := 'c:\faktura.pdf';

Text_Subject := 'Faktura no. '+Rec."No.";
Text_Body := 'Due date : '+FORMAT(Rec."Due Date");

// NewMessage('info@rainerbay.dk','info@rainerbay.dk',Text_Subject,Text_Body,AttatchedFileName,TRUE);

::.

// Where "NewMessage" is a procedure in the Codeunit.
Kind Regards

E-mail: info@rainerbay.dk
Skype: rainerbaydk

Comments

  • leegeorge_hughesleegeorge_hughes Member Posts: 2
    How are you creating the pdf file - is it via pdf995???

    Try doing this before creating the file:

    if exists(filename) then
    erase(filename)


    the other thing to watch for is that you give the OS time to save the attachment - try doing a repeat until with a sleep command (and maybe a yield to give the OS chance to do its stuff) until the file exists.
  • hedegaardhedegaard Member Posts: 25
    Hi Rainer,

    the problem is the REPORT.RUN

    If you do not use RUNMODAL the code will continue to run while the report is generated. So when the "New Message" code is run the report is not finished yet.

    If you use REPORT.RUNMODAL the system will wait for a reponse to the print before it continues.

    br
    Anders
  • RainerRainer Member Posts: 103
    It is pdf995 I use, and I solved the problem. It is exactly becaurse the PDF file is not "sent" to its destination yet, while the mail is generated.

    I guess its while I still use the free pdf995 with PopUps.. I put in a little "wait" in the code..and wupty it works.

    Thanks alot..
    Kind Regards

    E-mail: info@rainerbay.dk
    Skype: rainerbaydk
Sign In or Register to comment.