Applies to BPS version 8.3.x; Author: Karol Woźniak
Actions that generate Word and Excel documents offer a simple of adding attachments to a Workflow element. By using BPS Word Add-In we gain the ability to create dynamic documents which obtain up-to-date values directly from the desired form fields.
Thanks to the Convert Word to PDF action, we can add easily add attachments to elements that can be opened by any user, on practically any device without the need for MS Office.
After registering a workflow element, in the second step (i.e. after Supervisor approval) a .PDF attachment will be added, generated based on a dynamic .DOCX template created with BPS Word Add-In.
An attachment generated this way will be added to attachment category: „PDF”.
In order to successfully implement the scenario mentioned above, the first step is to design a .DOCX template using BPS Word Add-In and place it in a SharePoint library.
An installation guide for BPS Word Add-In can be found [here].
A quick guide on how to use BPS Word Add-In to create .DOCX templates can be found [here].
Sample template used for the purpose of this article:
After creating a similar template (in .docx format), add it to the SharePoint library and copy its URL address.
In the process node, go to Variables and create a new variable with the .docx template URL as the Shared value – This is for convenience, with the URL address stored in a variable we will be able to use a reference tag instead of entering the address manually.
For the next part of the setup, we need a new Attachment attribute for storing attachment categories – Add a new Attachment attribute, that uses a Fixed values list as its Data source. Add the following values (only PDF and TEMP are essential).
Elements necessary to correctly configure the “Generate…” and “Convert…” actions as seen on a process tree:
It is now time to configure the three key actions which will carry out the entire procedure. Got to the desire workflow and select a step (here we edit the start step), now add three On Path actions:
- Generate a Word file – This action will generate a .docx file based on the dynamic template in the SharePoint library, taking values from current form fields. Generated Word documents will be assigned to the TEMP category so that they can be easily deleted later.
- Convert Word to PDF – This action will convert the generated .docx document into PDF format. PDF files created from Word documents will be assigned to the PDF category.
- Run an SQL procedure – This will serve as a cleaner action, once a document is converted to PDF it becomes obsolete. This action will delete the unneeded files from the TEMP category (or any other specified), leaving only the PDF documents (in the PDF category).
First, we will set up the Generate a Word file action, the key configuration settings for this action are:
- Mode – Since we want to generate a new document, select Create new file.
- Template – Select From document library, this will allow you to provide the address of the SharePoint library containing the template.
- Document template – The link to the SharePoint library, instead of entering the address manually, use the reference tag to the variable containing the address (from the tree to the right, select Variables -> Process -> the variable created earlier).
- File name – Using reference tags, you can construct a unique dynamically generated name for each attachment.
- Category – All files generated by this action should be assigned to the TEMP category so that they may be cleaned out later.
Next, we will set up the Convert Word to PDF action to take generated documents from the TEMP category and convert them to PDF, and assign them a new category.
The configuration for this action can be seen below, the important things to note here are the source category (we used TEMP) and the target category for the new attachments (we used PDF). Everything else is left at the default value.
The final action which we want to use is a cleaner action which will sweep out the redundant docx documents. In our case, the Word files we generated were put in the TEMP category, so we will construct a Run an SQL procedure action which will delete all documents from this category that also have a .docx extension.
DELETE FROM dbo.WFDataAttachmets WHERE ATT_ID IN
(SELECT ATT_ID from dbo.WFDataAttachmets
WHERE ATT_FileType = ‘.docx’
AND dbo.ClearWFElemID(ATT_Attribute1) = ‘TEMP’)
After saving the process, go to the SharePoint form and launch a new workflow element.
After transitioning to the second step, the workflow element now has a PDF attachment.
The deleted .docx file can still be viewed in the Element history and downloaded to your drive if such a need arises. It won’t be visible on the form underneath the attachment panel, however.
Here is a preview of the generated PDF file, visible on the SharePoint form:
This scenario can be easily modified to generate more documents. Simply replicate the Generate a Word file and Convert Word to PDF actions and also set the correct URL addresses to templates. The action for cleaning docx files from the TEMP category can remain unchanged.