Introduction

The latest How To topics are available in the K2 Five User Guide or the K2 Cloud User Guide’s How to section.

This Knowledge Base article describes how to attach a PDF file to an E-mail Event in a workflow.

Audience
  • Developers
  • Form Designers
Required Knowledge
  • Views and Forms
  • Rules
  • Controls
  • Workflow

A PDF file can be created using the Save as PDF control. For more information on the Save as PDF control, see the following Knowledge Base articles : 

KB001361 - How to use Rule Actions to execute a custom control method

KB001378 - How to use the synchronous and asynchronous execution options of the Save as PDF control 

KB001394 - How to attach a PDF file to an E-mail Event in a workflow using a Form Parameter

Example Scenario

In the scenario below we are using a Form with a Save as PDF control. We then create a workflow and add a Data Field. An E-mail event is used to attach the PDF file created to the E-mail. The PDF control is then linked to the Data Field in the workflow start rule in the Rule Designer. 

Follow the steps below to set up the scenario:

  1. Create a SmartObject to be used in a View. We used a Leave SmartObject
  2. Auto generate an Item View and a Form from the SmartObject
  3. Edit the View, remove all the buttons except for the Create button
  4. Rename the Create button to Submit and save the View
  5. Edit the Form, navigate to the Layout step and drag the Save as PDF control onto the canvas.
    Image
  6. Navigate to the Rules and edit the when SubmitButton is Clicked Rule
  7. Add the following Rule Action:
    Actions: Execute a control's method

    Image
  8. Save the Rule
  9. Save the Form and create a Workflow named Leave Application from the Form
  10. On the Data Fields screen of the Workflow Settings, create a Data Field of Type Integer as shown below. The Type used here should correlate to the PDF File ID type which is Autonumber.   
    Image
  11. On the Start Form screen, ensure to select the Rule when SubmitButton is Clicked. This will ensure that the data is created and the PDF is captured before starting the workflow 
    Image
  12. Finish the wizard 
  13. We then add a User Task to the workflow with Approve and Decline outcomes. Configure the rest of the wizard
  14. Drag the Send E-mail event onto the Approve outcome. Provide details and then drag the PDF Load method into the Attachments field as shown below  
    Image
  15. Map the Data Field to the Load method 
    Image
  16. The PDF Load method is displayed in the Attachments field. Finish the wizard 
    Image
  17. Drag a Placeholder event onto the Decline step in the workflow
  18. The workflow represents the following:
    Image
  19. Save and deploy the workflow
  20. Edit the Form and navigate to the Rules.

  21. Edit the when SubmitButton is Clicked Rule of the Leave Application State. This is the state that will start the workflow

    Image
  22. Click on configure next to the Action start the Leave Application Workflow
    Image
  23. Map the PDF control to the Workflow Data Field as shown below
    Image
  24. Save the Form
  25. Run the Form and capture the required details, then click Submit
    Image
  26. Open the worklist item, select the Action Approve and click the Submit button
  27. The E-mail is sent to the recipient with the PDF attached
    Image
  28. Open the PDF to view the details captured
    Image