Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Sending email with attachment to the vendor after the status is approved

Posted on by 4,184

Hi

I'm using Purchase order send approval workflow. once the approval request is approved by the approver i.e status of approval entries changes to Approved. An email with purchase order details as an attachment should be sent to the Vendor.

I've written code for the email with attachment but how to trigger this code? 

can someone help.

*This post is locked for comments

  • Verified answer
    CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hi Binesh,

    Thanks for so much help!

    I created another variable Rec_Purchase with record Purchase Header and saved my PDF using Record Rec_Purchase as Filename. This solution worked and I get my pdf with details pertaining to my Purchase Order number.

    email3.png

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hello,

    Declare report Variable of Report 405
    ReportVariable.SETTABLEVIEW(PurchaseHeader)


    For reference see bellow:

    -----------------

    SalesQuotePdf(DocumentNo : Code[20];PdfDocPath : Text[250])
    CLEAR(QuoteReport);
    SalesHeader.RESET;
    SalesHeader.SETRANGE("Document Type",SalesHeader."Document Type"::Quote);
    SalesHeader.SETRANGE("No.",DocumentNo);
    IF SalesHeader.FINDFIRST THEN BEGIN
    QuoteReport.USEREQUESTPAGE(FALSE);
    QuoteReport.SETTABLEVIEW(SalesHeader);
    Path := 'C:\Temp\'+PdfDocPath;
    QuoteReport.SAVEASPDF(Path);
    DocSetup.GET;
    DocSetup.TESTFIELD(Exportpath);

    FromFile := Path;
    ToFile := DocSetup.Exportpath + PdfDocPath;
    IF FILE.EXISTS(FromFile) THEN BEGIN
    MoveQuoteFile(FromFile,ToFile);
    END;
    IF FileMgt.ClientFileExists(Path) THEN
    ERASE(Path);
    END;

    Note:

  • CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hi Binesh,

    I followed your code and called my function from purchase order form action for testing purpose. 

    still in my pdf I get record details of all purchase orders.

    5516.email2.JPG

    5516.email2.JPG

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hello Chris,

    How you called SendEmailWithAttachment, Send your code, because you are passing the Purchase header, 

    and if you didn't filter correctly, then it pulled all records.

    You have to filter purchase Header with particular no. or whatever you want, that's it.

  • CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: Sending email with attachment to the vendor after the status is approved

    email1.JPG

  • CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hi Binesh

    Thanks for you reply. My code fetches the purchase order number and also mail is sent successfully but when I open my pdf document in the mail. I receive details of all purchase orders.

    is there any means to filter and send only details of my purchase order in the pdf rather than sending all.

  • Verified answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hello Chris,

    I Checked in my DB with Sales Header, its working, See the bellow Image.

    Do one thing Debug your code, it might be chances to:

    >   Not getting the Purchase Order No.

    > IF in your PO no records then, system won't create PDF also.

    > Better to filter one PO like me that are exist and then try it.

    > also check in PO no, is any special char or spaces in last.

     

    1805.2.png

    1805.2.png

  • CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hi Binesh,

    I'm finding the above post difficult to understand. can you please explain it again.

    I need to get the purchase order number and then attach the purchase order as a pdf document.

    can you tell me what modification need to be done to my code. cause my code works successful without using workflows.

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hello Chris,

    Better to use FileMgmt Codeunit for copying the server file in to client.

    or you can use bellow solution as per ur requirements

    OR use for saving

    FileName := FileMgt.ClientTempFileName('PDF');

    //Bellow code are working.,

    IF YourReport.SAVEASPDF(TotalFileNameL) THEN BEGIN

     COMMIT;

     IF FileMgt.ClientFileExists(TotalFileNameL) THEN BEGIN

       SendMailTest('WIRE',MonthL,TotalFileNameL);

     END  ELSE

       ERROR(Text012,TotalFileNameL);

    END ELSE

     ERROR(Text013);

    //Find the screenshot for SendMail. its working

    2627.2.png

    2627.2.png

  • CDsilva Profile Picture
    CDsilva 4,184 on at
    RE: Sending email with attachment to the vendor after the status is approved

    Hi

    I created a workflow response for 'Purchase order send approval workflow' and added it to the workflow in the front end. I need to attach the document as .pdf file. I've written the below code but it work if I use it normally without a workflow i.e on a Action. but doesn't work with the workflow. 

    email.JPG

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,232 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans