Report by E-Mail. Attach e-mail address.

NagiNagi Member Posts: 151
Hi,

My questions is this. When running report 205 Order Confirmation and selecting File -> Send -> Report by E-Mail, NAV 4.2 does not automatically attach the customer's e-mail address from the customer card. Is there an easy way to accomplish this? I've been trying to debug to see if the option Report by E-Mail fires a function or codeunit in NAV where I could easily attach the e-mail address, but I've been unable to find such a thing. Does this mean that the Report by E-Mail option is in the program core? I suppose I could create my own e-mail function using codeunit 397 Mail, but I would like to use the Report by E-Mail option because that's what the customer is used to using and it would also lessen my workload.

If anybody has any suggestions on this, then I would be grateful.

Cheers!

Answers

  • WaldoWaldo Member Posts: 3,412
    It is indeed something that is in the code of the client. Something we can't use.

    What is an alternative:
    Use the REPORT.SAVEASHTML. With this function, you can save to a temp-directory (for example: ENVIRON('TEMP')), and use the mail codeunit to create a mail and attach the temp file...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • NagiNagi Member Posts: 151
    Thanks Waldo, I was thinking that maybe I had to do it like that. I appreciate your help. Cheers!
  • WaldoWaldo Member Posts: 3,412
    No prob, man.
    Good luck and it's always nice that people post their solution when ready :wink:.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • NagiNagi Member Posts: 151
    Well, the solution was more or less like Waldo's suggestion. In the sales header table, I added a function that calls codeunit mail. That codeunit is quite easy to understand, just take a look at the parameters in the NewMessage function. My function saves report 205 as html using SAVEASHTML. The html file is saved to a temp folder and the e-mail adress is fetched from the customer card.

    Biggest problem was attaching more than one file. This was necessary because the customer has logo and signature *.bmp files. The solution was to copy the NewMessage function and create an identical one with two more "AttachFile" parameters. Of course, it's also necessary to copy the C/AL code that handles the AttachFile parameter. Also, the *.bmp files must be named pic1.bmp, pic2.bmp, etc. in the order that the report processes the pictures.

    The full code looks like this... I hope it can prove useful to someone else.
    //Function SendByMail(parDocType : Integer;parDocNo : Code[20])
    
    CompanyInfo.GET;
    SalesSetup.GET;
    SalesSetup.TESTFIELD("Order Confirmation E-Mail Temp");
    SalesHeader.SETRANGE("Document Type",parDocType);
    SalesHeader.SETRANGE("No.",parDocNo);
    IF SalesHeader.FINDFIRST THEN BEGIN
      IF (UserSetup.GET(USERID)) AND (UserSetup."Salesperson/Purch. Code" = SalesHeader."Salesperson Code") THEN
        UserSetup.CALCFIELDS(Signature);
      IF UserSetup.Signature.HASVALUE = TRUE THEN BEGIN
        SignatureFileName := SalesSetup."Order Confirmation E-Mail Temp" + 'pic2.bmp';
        UserSetup.Signature.EXPORT(SignatureFileName);
      END;
      LogoFileName := SalesSetup."Order Confirmation E-Mail Temp" + 'pic1.bmp';
      CompanyInfo.CALCFIELDS(Picture);
      IF CompanyInfo.Picture.HASVALUE = TRUE THEN
        CompanyInfo.Picture.EXPORT(LogoFileName);
      ReportSelections.RESET;
      ReportSelections.SETRANGE(Usage,ReportSelections.Usage::"S.Order");
      IF ReportSelections.FINDFIRST THEN
        ReportID := ReportSelections."Report ID";
      FileName := SalesSetup."Order Confirmation E-Mail Temp" + 'Ordrebekreftelse.html';
      REPORT.SAVEASHTML(ReportID,FileName,TRUE,SalesHeader);
      Cust.GET("Bill-to Customer No.");
      IF Cust."E-Mail" <> '' THEN
        EmailAddress := Cust."E-Mail";
      Mail.NewMessage2(EmailAddress,'','Order Confirmation','',FileName,SignatureFileName,LogoFileName,TRUE);
      IF EXISTS(FileName) THEN
        ERASE(FileName);
      IF EXISTS(LogoFileName) THEN
        ERASE(LogoFileName);
      IF EXISTS(SignatureFileName) THEN
        ERASE(SignatureFileName);
    END;
    
Sign In or Register to comment.