24 May’17

D365 Business Central

Send Email with attachment to the vendor as a response in Purchase order workflow in NAV 2017

Introduction:

In this article, a workflow response is created in the standard purchase order workflow. This response sends an email to the vendor after release of the purchase order i.e when the send approval request of the purchase order is approved by the authorized approver, the status of the purchase order changes to Released  afterwhich an email is sent with  attachment in a .pdf format to the vendor.

Pre-requisites

1.Microsoft Dynamics NAV 2017

Steps:

1. Configure smtp mail setup in the front end where you need to enter the sender’s email id and password.

2. Now to create a workflow response we need to create a global function in a new codeunit. Navigate to View tab select C/AL Globals or (Ctrl+G). click on the functions tab and under the Name type the function name, by default the function is a local function.

3. To make it a global function, select the function ‘SendEmailCode’ and click on view tab then click on properties. Set the Local to No, this will make the function global.

  • Now click on the function then click on Locals button placed on the right side. Click on the return value tab and set return type as code and length as 128.

  • This function calls another function ‘SendEmail’

4. Create another global function with another name in this article I’ve used ‘SendEmail’. Set parameter to the record ‘Purchase Header’ and enable it as a variable.

5. In the below code, we first fetch the vendor email id and set it to a variable VendEmail.

  • We use the FileManagement codeunit and set the ServerTempFileName as a ‘pdf’ file.
  • We then save the report as pdf file.
  •  We then use SMTPMail codeunit, The SMTPMAIL.CreateMessage sets the sender’s email id and recepients email id, subject of the email
  •  SMTP.AddAttachment function attaches the purchase order in  a .pdf format.
  • In SMTPMail.AppendBody function we can specify the body of the email.
  • SMTP.Send functions sends the email.

6. Now the response created of sending email to the vendors need to be added to the workflow response library.

  •  Create a global function, in the properties of the function click on the event field and select subscriber.
  • In the Event Publisher object select the Workflow Response Handling codeunit (codeunit no. 1521)
  •  In the Event Function field select OnAddworkflowResponseToLibrary.
  •  Select the function and click on the Locals button and in the variables tab, create a variable for codeunit Workflow Response Handling.
  • In the below code, we add the response to workflow library with name SendEmailVendor. This name is a text constant

7. Now to execute the response we need to create a global function.

  • Create a global function, in the properties of the function click on the event field and select subscriber.
  • In the Event Publisher object select the Workflow Response Handling codeunit (codeunit no. 1521)
  • In the Event Function field select OnExecuteWorkflowResponse.
  •  In the Locals for this function, in the variable tab create a variable for the record ‘workflow response’.

8. In the Dynamics NAV front end , navigate to workflows from the search bar. In the purchase order approval workflow, add the response ‘Send Email To Vendor’ then enable the workflow.

9. Navigate to Purchase order from the search bar and click on Send approval request button on the menu bar.

10. The email is sent to the vendor.


 

Written by

Chris D'Silva

Software Developer

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • How to enable Document ID in SharePoint Online

    16 May’ 2019

    Introduction: As you know that SharePoint Online can be used as a document management platform and with the help of Docu...

    Read more
  • Count Number of files in SharePoint folder

    15 May’ 2019

    Introduction: This blog explains how to Count No of files in SharePoint folder using MS Flow. Steps to be followed:Sel...

    Read more
  • Professional Services Automation (PSA) for CPA firms

    14 May’ 2019

    With the evolution of Technology, every industry is getting process oriented and so are CPA firms getting more organized...

    Read more
  • What if the Resource Requirement Still appears post the task is deleted from Schedule (WBS) in PSA V3?

    13 May’ 2019

    Problem Definition: I have observed a fact in PSA that when the task in PSA Schedule (WBS) is deleted, the corresponding...

    Read more
  • Discount Settings for D365 Sales Line Items – Line Items or Per Unit?

    10 May’ 2019

    For Line Item entities Opportunity Products, Quotes Products, Order Products or Invoice Products, you can chose what typ...

    Read more
  • We respect your privacy.
  • This field is for validation purposes and should be left unchanged.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close