Prerequisites
A WorkBuddy Form
Word Document with desired PDF layout
The process of generating a pdf of a submitted form involves taking responses from the form and inserting them into specific locations in a pre-defined pdf template. This article will guide you through adding a template to a form in order to customise the pdf for that form.
Your word document will also have fixed text being the information labels. A blank version of the required pdf should be made. You can use a blank existing form as a starting layout or create a layout from scratch.
When creating a pdf template for a Form you paste the questions from the form into the word document. This is done via merge fields which are short text references to the questions in the form.
The completed word document is then uploaded to the form. When the form is submitted, a pdf is created by replacing the merge fields in the document with the responses from the form.
This article covers Document Theme usage for forms, for more info on designing forms see Designing Forms.
Optimising The Form
Optimising the form can allow for more convenient management of Merge Fields when creating a Document Theme.
We recommend using a naming convention when creating the Advanced Names and Unique Name fields in a form. A naming convention should result in Merge Fields that are short and easy to refer to. Long merge field names will make the Document Theme hard to read when designing but will still render fine.
Word Editing
To access the merge fields, you need to set the Print Layout to Document Themes.
To view the merge fields for your form, select the "View available merge fields" button. The Available Merge Fields column will appear on the right of the screen.
Merge fields follow a page -> section -> question syntax meaning that the name of the page, section, and the unique name field in a question will compose the name of a merge field. An example of this would be pageOne_sectionOne_question.
The screenshot below has some example merge fields that would be found once selecting the "View available merge fields" button.
The merge fields are grouped into Form and Form Metadata. There will be additional groups for any repeat sections in your form. Inside each group the fields are sorted alphabetically.
The Form group contains the merge fields for the questions you added to your form.
The Form Metadata group contains standard merge fields that are generated for every form. eg, who completed the form and when it was completed.
Expand a group by clicking on it's title. You can select a merge field to copy the field name to the clipboard.
When pasting a merge field in a word document, it needs to be surrounded with angled brackets and square brackets, eg: <<[pageOne_sectionOne_question]>>. Merge fields can be copied to the clipboard with the bracketed syntax by selecting the Word icon next to the merge field.
The specific angled bracket syntax must be used as that is how the Document Theme knows where to put the form question response. The left image below shows a merge field in a word document, the right shows the output of a completed form with the same template.
For most questions, such as Short Test, the answer directly replaces the merge field.
Date fields can have extra syntax to define how the date should be displayed.
Other questions, such as images or a multi-select multiple choice, need a "foreach" to display the user's response correctly. Examples of these are provided below.
For detailed information on formatting merge fields for text, images, tables, and conditional rendering see Using Word templates in Document Themes.
Form Metadata Merge Fields
The table below lists the available merge fields and their descriptions under the "Form Metadata" tab.
Merge Field Name | Merge Field | Description |
Completed | <<[Completed]>> | Whether the form response is completed |
Created Date (UTC) | <<[CreatedDate]>> | Date when the form response was created |
Submitted By | <<[SubmittedBy]>> | Name of the person who submitted the form |
Submitted On | <<[SubmittedOn]>> | Date when the form was submitted |
Submitted On (UTC) | <<[SubmittedOnUTC]>> | Date when the form was submitted |
Updated Date (UTC) | <<[UpdatedDate]>> | Date when the form response was last updated |
Custom Multiple Choice Questions in Forms
Custom Multiple Choice questions have a unique field compared to other Form questions. The unique field is the "Mode" field.
The options inside of the "Mode" field are "Single" and "Multiple". The "Single" field will result in Custom Multiple Choice questions that can only have one answer from the list. The "Multiple" field will alternatively allow for one or more answers to be selected within the list.
Custom Multiple Choice questions that are set to "Multiple" will result in comma separated answers when rendered as a Merge Field. An example of a comma separated answer in a form, a merge field and rendered in a Document Theme can be found in the screenshot below:
These comma separated answers can be handled using a foreach statement and a split method. A foreach statement is used to loop through all the answers of a question and the split method is used to filter these answers. An example a Merge Field setup for this use case would be:
<<foreach [item in page_section_customMultipleChoice.Split(',')]>>
<<[item]>>
<</foreach>>
The snippet above is splitting the return of the merge field page_section_customMultipleChoice by the commas in the response. Each split response is referable within the foreach block by the variable item. The foreach will loop through all the split items and render them based on how many there are.
It is also important to note that the advanced name field of a repeat section is the equivalent of the unique name field in other form entities.
A foreach statement can also be used for handling multiple images in the same question, multi-select custom multiple choice questions, or generating rows dynamically in a table. Examples of these techniques can be found in the article Using Word templates in Document Themes.
Testing The Form
The public status of a form allows for the form to be completed. By navigating to the entity that the form will merge with, you can fill out the form. The example below focuses on a Form that merges with stage. First navigate to the stage, then the Activities tab, then press the dropdown menu next to the plus and selecting "Form".
This will prompt a window to appear in the middle of the screen where you can navigate to or search for the form you want to test. The form can either be copied as a link to share and test on a different device, or can be filled out locally using the "Fill Out" button.
Once the form is completed, exit the window and the completed form will appear in the activities tab of the Stage it was completed in. The same process will apply for Forms that merge with other entities.
Once the preview is pressed on it will show the completed Form in the Document Theme layout with all the applied merge fields. There is also a toggle at the bottom of the screen that allows you to also view the default generated WorkBuddy completed form.
Forms that are created and filled out as tests can be deleted from the activities tab by clicking the three dots in the bottom right corner of the form response preview. This requires the Jobs -> Advanced Rights -> Manage Activity security role.
Common Errors in Document Themes
Errors in Document Themes can manifest in different ways.
The most common way of determining an error in your Document Theme is when the syntax of the merge fields renders in the PDF, rather than the desired form information.
When this happens, scan through the PDF document. Attached to one of the merge fields in the document will be a bolded error message. If a PDF is not rendering, it may be an unclosed <</foreach>> statement that is causing an infinite loop.
The table below explains some of the more common errors with Document Themes and potential solutions:
Common Error | Meaning | Fix |
Expression Expected | There is an unclosed merge field somewhere in the document, usually where the error message occurs | Add the correct angled bracket or square bracket to the merge field |
Can not copy or remove document contents between different stories or cells of different tables | The output of the merge field expands beyond the borders of the table. This usually occurs with images. | Adjust the textbox in the table or expand the table to fit the textbox |
WorkBuddy Support can help you diagnose issues if you can't identify the error in a document theme.
Result
You can now create merge field embedded Word Document templates to format WorkBuddy form responses according to your specifications.
What's next? See Using Word templates in Document Themes for advanced techniques.







