Generating Word Quote Template in Dynamics CRM 2016

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.

Document Generation in dynamics crm 2016

  • 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.

Document Generation in dynamics crm 2016 Available Templetes

  • 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”.

Create Template for CRM Data

 

  • 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.

Relationship Page in Dynamics CRM Document Generation 2016

 

  • 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.

Enable Developer Tab in MS Word

 

  • After clicking OK the Developer Tab will appear in Ribbon bar.

Developer Tab in MS Word

 

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”

Insert Column Control

  • Do not make any textual changes to content control. You can format changes like making it bold.

textual changes

  • Turn Off Auto Correct in MS Word.

1. Go to File > Options > Proofing > AutoCorrect Options.

disable auto correct 1

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

disable auto correct 2

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 Pane Developer Tab in MS Word

  • 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.

 

Document Generation Template XML Mapping Pane

 

  • 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.

Insert Column Control

 

  • 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.
1. customeridname
2. name
3. effectivefrom
4. effectiveto
5. owneridname
6. quotenumber
7. discountpercentage
8. discountamount
9. totallineitemamount
10.totaltax
11.totalamount

Document Generation Template

 

  • 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.

Quote Products Grid

  • 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.

Quote Products

 

  • Select and add respective Entity Fields in second row of table. We have added the following fields.

1. isproductoverridden
true for Write-In Product and False for Existing Product.
2. productidname
Name of Existing Product.
3. productdescription
Description of Write-In Product
4. priceperunit
Unit Price of Product
5. quantity
Quantity of product
6. extendedamount
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.

selected row

 

  • 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.

repeating

 

Step 4: Upload Word Template to CRM

  • Save the template and click on “Upload Template” button and upload the word template.

Upload

 

  • Uploaded template will appear in “Available Template View”.

uploadedStep 5: Generate Word Document From Template

  • To generate a document open any quote.
  • ClickMore (…) > Word Templates, and then under Word Templates select the template “Quote For Customers”

generate quote

 

 

  • A word document will be generated and downloaded to your computer based on the template you have created.

generated document

 

You can download the word template from here.  Quote For Customers Template.

See also:  Auto Generate Word Template in Dynamics CRM 2016 and attach in Email

 



17 Comments

  • Alex

    I am trying to create a Quote Template. I was able to include most of the entities required, but the Existing Product ID and Existing Product Description is not listed in the XML mapping. How do I include those?

  • Martin

    Can you initiate a merge via the API? I know you can do this via standard workflow step, but it seems to me that this is somewhat limited. We typically want to email a document like this or do something other than glue it to a record as an attachment on note, or have the user download it. As a BA (not a dev) I am trying to identify if this is in the API or not. We would want to chain the merge with creation of a draft email and then allow the configured workflow to do what it needs to the email for subject and addressing etc.

  • Rick N

    This is very helpful. But how can I get a custom Product field like PartNumber to populate the same custom field in Quote Product when a product is added to a quote? The custom field appears in quote_details and I’ve added it to the template, but there’s no data in it.

    • admin

      There is no Out of the Box way to set data in fields at runtime.
      You can do this using plugin or javascript to set PartNumber field in QuoteProduct.

  • Viswanath

    How can i place the Lookup in the subgrid in the template document for N to N relationship.

  • Johan

    Thanks for the post. Is there a way to control the sorting order in which the related (many) items will be published in the Word doc? They seem to appear in a random order.
    Thx

  • […] our previous blog post we covered how to create a custom Microsoft Word template to generate Customer Ready Quote using […]

  • […] our previous blog post we covered how to create a custom Microsoft Word template to generate Customer Ready Quote using […]

  • Ana

    Thank you! I was really helpful.
    I’d like to know also how to delete the uploaded template (from Settings->templates the uploaded templates are not shown).

    • Martin

      To delete personal templates you need to do an advanced find I believe. This is half baked in my opinion. As is the inability to update the template within the record. If you are trying to use templates in workflows, each time you revise the template this means new template which means change to workflow. Nasty!

  • Kristopher Turek

    I am having issues where the total amount is not populating… is this a bug?

  • Paul Shore

    Don’t forget that you need to have the 1:N relationship field populated on the N Entity side with its corresponding 1 Entity lookup on the form. It’s not enough for the relationship to just exist like a subgrid where you can just select all the records, they need to be related records.

  • Hi,

    Thanks for the guide and sharing your knowledge.

    Got a question, can you filter on the quotedetails/quote products? E.g. so that it only shows some of these?
    E.g. I have marked which quote products are needed, with a checkbox, which I want to show in one tabel and then want to show in another tabel the ones that are not marked as needed?

    -Thue

  • Yvan Leclerc

    Quick question: Let’s say I have a template that is working great. Now, I want to include a brand new field that I just created to it. Is there anyway to reresh the list of mapping fields in Word instead of re-doing the whole template?

  • Fred Ganyaupfu

    Thank you so much for this detailed article. I have picked up a problem with my quantity field. When I type 20.00 on CRM and download my template the quantity is displayed as 20 000 000 000. How may i fix this issue.

Leave a Reply

Request a Free Demo
Enter Your Information below and we will get back to you within few hours