How To: Attach a PDF File to an Email Step in a Workflow

In the following scenario, you attach a PDF file to an email in a workflow. To do this, you use a form parameter and rules along with the Save As PDF control, and then map the parameter to a data field used to attach the PDF to the email using a Send Email step.

Steps

Follow the steps below to set up the scenario:

  1. Open K2 Designer and create a SmartObject called Quote with following properties:

    Customer SmartObject PropertyTypeKeyRequiredUnique
    IDAutonumberYesNoYes
    Quote DetailsTextNoNoNo
    Quote AmountNumberNoNoNo
  2. Autogenerate an Item View and a Form using the SmartObject.
  3. Edit the view and remove all buttons except Create.
  4. Rename the Create button to Submit and save the view.
  5. Edit the form, go to the Layout tab, and drag the Save as PDF control onto the canvas.
  6. Click the Parameters tab and add a parameter called PDF ID. Configure the Data Type as Number for this scenario. It is important to match the parameter data type with what the load method of the Save As PDF SmartObject.
  7. Navigate to the Rules tab and edit the when On Quote Item, when Submit Button is Clicked rule.
  8. Navigate to the Actions tab and add the Execute a control's method action. Select the Save PDF method of the Save As PDF control.
  9. Add a Transfer Data and a Show a Message action to the rule.
  10. On the Transfer Data action, click configure and map the Save as PDF control to the PDF ID parameter as shown below, and then click OK.
  11. On the Show a Message action, click configure. Type Submitted successfully in the Body and click OK.
  12. Save the form and create a new workflow called Quote Approval Workflow.
  13. Click the Start event and then click Edit... under How will this workflow be started?.
  14. Click Next on the Start Workflow from a Form page.
  15. Select the Do it for me! option and then click Next.
  16. Click Save and Finish. A new workflow state is created called Quote Approval Workflow.
  17. Click OK.
  18. Select the Start event and create a variable called ID with a Number data type.
  19. Save and Deploy the workflow.
  20. Edit the Quote form and navigate to the Rules tab. Select the Quote Approval Workflow state from the States section. Double click the On Quote Item, when Submit Button is Clicked rule.
  21. Click configure on the then start the Quote Approval Workflow Workflow action.
  22. Drag the PDF ID form parameter from the Context Browser to the ID field in the Workflow Fields section, and then click Finish.
  23. Click OK and Finish.
  24. Check in the Quote form.
  25. Edit the Quote Approval Workflow.
  26. Drag the Task step from the Basic section on to the canvas. Click the < icon on the left to open the Task tab.
  27. Click the Both link in the Actions section of the Task tab. This creates two actions called Approve and Reject.
  28. Drag a Decision step from the Logic section on to the canvas. Connect the Task step to the Decision step.
  29. Drag a Send Email step from the Basic section to the Approved action. Click the < icon to open to the Send Email tab.
  30. Add a Subject and Body . Click Add Attachment in the Attachment section.
  31. Click the Context Browser icon to expand the Context Browser and drag the PDF File > Load method from the SmartObjects section.
  32. Drag the ID variable from the Fields section in to the ID field of the Edit SmartField section.
  33. Drag a Placeholder step from the Basic section in to the Rejected action.
  34. Drag an End step from the Logic section on to the canvas and connect the Approved and Rejected actions to it.
  35. Save and Deploy the workflow.
  36. Run the Quote form, enter values for Quote Details and Quote Amount, and then click Submit.
  37. The Submitted Successfully message is displayed. Click OK.
  38. Open K2 Workspace, select Approve, and then click Submit.
  39. The email is sent with the attached PDF.
  40. Open the PDF to view the quote details.