In this blog post we will cover how to create a custom Microsoft Word template to generate Customer Ready Quote using Document Generation feature introduced in Dynamics CRM 2016. Users can create Word templates for letters, agreements, quotes, invoices and other documents automatically populated with CRM data and generate document in just a single click.
Below is step by step guide to create custom Word Template from Quote entity.
Step 1: Create Word Template
The first step is the creation of Microsoft Word template.
- From the Settings page. Go to Settings > Templates you will be able to see Document Templates options which was not there before Dynamics CRM 2016 update.
- Click on Document Templates and you can see there are already some built-in document templates available (both MS Word and MS Excel based), and you can make custom templates, upload them and generate documents based on these templates.
- Click on New (+) button to create a new template.
- After that a windows will appear Select “Word Template” as our document will be word based.
- We will get data from quote entity so select “Quote” in Filter by Entity drop down.
- Click on “Select Entity”.
- After that the relationship selection page will appear. To fully understand this relationships you should have the understanding of CRM data structure. The relationships we select on this screen will determine what entities and fields are available later when you define the Word template.
- Selected 1: N relationship of Quote with “Quote Products” , as one quote can have many Quote Products associated with it, and only select relationships you need to add CRM data to the Word template.
- Click on Download Template button after that a word file will be downloaded to your local computer with exported entity included as XML data.
Step 2: Enabling Developer Tab in MS Word
After downloading the template open file in Microsoft Word, this will be a blank document.
To make changes and add XML data you have to enable the developer tab in MS Word.
- Go to File > Options > Customize Ribbon, and then enable Developer.
- After clicking OK the Developer Tab will appear in Ribbon bar.
Issues While Editing Template and Solutions.
While editing the template there are few things which can cause MS Word to freeze, requiring you to use Task Manager to stop Word. For example if you insert a content control (Entity Field) other than Picture or Plain Text or you make a textual change, such as changing the capitalization or adding text, to a content control. These changes can occur through AutoCorrect as well as user edits.
By default, Microsoft Word AutoCorrect capitalizes sentences. When you add a content control field, Word sees it as a new sentence and will capitalize it when focus shifts away from the field.
To prevent these issues below are some steps and considerations.
- Only add Entity fields as “Picture” or “Plain Text”
- Do not make any textual changes to content control. You can format changes like making it bold.
- Turn Off Auto Correct in MS Word.
1. Go to File > Options > Proofing > AutoCorrect Options.
2. Navigate to AutoCorrect tab and uncheck the Capitalize first letter of sentences and Automatically use suggestions from the spelling checker options.
3. Click OK
Step 3: Edit Word Template
The next step is to use XML Mapping Pane under Developer Tab to edit the Word Templates and populate it with CRM data.
- Click on Developer > XML Mapping Pane
- XML Mapping Pane will appear on the right side of Word Document, change default XML schema to CRM XML schema. It will begin with “urn:microsoft-crm/document-template/”. Quote entity will appear under it, expand the entity and you will see all its attributes and selected relationships.
- Right-click the entity field, and then click Insert Content Control > Plain Text.It will insert the CRM entity field in Word Template, the data for this field will be dynamically populated from Dynamics CRM.
- Add additional entity fields, add descriptive labels and text, and format the document. We have made a layout for Quote Document using these content Controls. The highlighted text in image below shows the quote entity fields. These will be populated dynamically at time of document generation.
We have used the following Quote Fields.
- The next step is to add all the Quote Products related to that Quote entity. For this make a table with two rows and five columns and add titles of CRM entity fields in first row that you want to display.
- To add the respective entity fields use 1: N relationship of Quote with “Quote Products” that we have selected at time of the creation of template. Scroll down in XML Mapping Pane and we have this relationship by the name of quote_details.
- Select and add respective Entity Fields in second row of table. We have added the following fields.
true for Write-In Product and False for Existing Product.
Name of Existing Product.
Description of Write-In Product
Unit Price of Product
Quantity of product
total amount ( Unit Price * Quantity)
The above content controls likely have multiple lines of data as they belong to 1:N relationship of Quote entity with Quote Products entity. To include all the data in your Word template, set these content controls to repeat.
Set content control fields to repeat
To set the rows of tables to repeat follow these steps.
- Select the entire table row in the table.
- In the XML Mapping Pane, right-click the relationship (quote_details) containing the content control fields, and then click Repeating. When you use the Word template in CRM to create a document, the table will populate with multiple rows of data.
Step 4: Upload Word Template to CRM
- Save the template and click on “Upload Template” button and upload the word template.
- Uploaded template will appear in “Available Template View”.
- To generate a document open any quote.
- ClickMore (…) > Word Templates, and then under Word Templates select the template “Quote For Customers”
- A word document will be generated and downloaded to your computer based on the template you have created.
You can download the word template from here. Quote For Customers Template.