Dynamics 365 Sales: Generate PDF from Word Templates

This week I was getting ready for a presentation for the Dynamics 365 user group, and while I was making sure everything in my instance was working correctly for the demo, I noticed that some new functionality had been added to the system. Before this update we were only able to generate PDFs from the quote entity, but to my surprise I noticed we can now enable this functionality for these entities in Dynamics 365 as well: Account, Contact, Lead, Opportunity, Sales Order and Invoice. For folks who don’t know what this means: we have the ability to push data from Dynamics 365 into a document. We can configure word templates to map the data fields and child records. The PDF generation allows users to create a PDF file vs a word document. In this article I’ll explain how to configure a word template for the opportunity entity. I’ll be using this word template as a quote that I can send to my customers.

Download Word Template

Before we can configure the word template, we first need to download a blank template that is connected to Dynamics 365. Navigate to Settings > Templates > Document Templates. Click the +New button on the command bar, this will bring up the ‘Create Template from Dynamics…’ window. From this window you can pick the template to create, you have the option between an excel template and a word template. Click on the Word Template button and select the entity you want to create a word template for. In this example I’m going to use the Opportunity Entity. Click the ‘Select Entity’ button.

NOTE: Excel templates are different from exporting raw data into excel. Exel templates can be pre-configured with pivot tables, pivot charts, filters, etc. Users can then push data from Dynamics 365 in these pre-configured excel sheets and analyse the data.

The next screen shows you the relationships that are available for this entity. You want to pick related entities so you can pull this data into the word document. I am going to pick the following relationships:

1:N Relationship
Entity Name: Opportunity Line | Schema Name: product_opportunities

N:1 Relationship
Entity Name: Account | Schema Name: opportunity_customer _account
Entity Name: Contact | Schema Name: opportunity_parent_contact
Entity Name: User | Schema Name: opportunity_owning_user

Click the ‘Download Template’ button and save the file. After the file has been downloaded open the file. At this point you can configure the form to look like a quote. (adding the tables, columns, company information, etc)

NOTE: If you have this setup in another word document, you can copy and paste it into the word template so you don’t have to start from scratch.

Configure Word Template to pull in Dynamics 365 Data

Click on the developer tab in Word. If you don’t see the developer tab: Click the File tab, go to Options > Customize Ribbon. Under Customize Ribbon and under Main Tabs, select the Developer check box.
Click the XML Mapping Pane button on the ribbon, then click on the dropdown on the right side and select the ‘urn:microsoft-crm/document-template/opportunity/3/’ from the drop down. Under ‘Document Template’, click the chevron next to ‘Opportunity’ to expand. Now you see all the fields related to the opportunity entity that can be used to add data from that field to the word template. If you scroll all the way down you’ll see the other entities we selected earlier:

product_opportunies: These are the products related to the opportunity. We will add them in the grid on the word template and repeat the rows
opportunity_customer_accounts: This is the account record populated in the customer field on the opportunity
opportunity_owning_user: The owner of the opportunity. This allows us to pull in user information like, email address, name, phone number, etc.
opportunity_parent_contact: This is the parent contact for the opportunity. I added this field to the form so that I can track the contact at the customer account.

We will add the account and contact information on the right hand side of the word template first. Expand opportunity_customer_accounts, and find the ‘name’ field. Put your mouse in the word document at the place you want to add the field, then right click on the name field, click ‘Insert Content Control’ and click ‘Plain Text’. You just added the account name field to the document. Add any other fields to the word template (I.E address, contact name, owner/sales person name, etc) the same way.

The next step is to add the opportunity products table to the document template. Expand product_opportunities. Enter the fields you want to add in the product table, like we added the account name field. (I.E quantity, productidname, priceperunit, manualdiscountamaount, extended amount). Select the entire row with opportunity product data, then (under XML mapping) right click on ‘product_opportunities’; click ‘Insert Content Control’ and select ‘repeating’. This will bring all the product opportunity lines from Dynamics 365 into the word template. Save the word template.

After we’re done configuring the word template we need to upload it to our Dynamics 365 instance. Navigate to Settings > Templates > Document Templates and click the ‘Upload Template’ button on the command bar. Upload the word template and give it an appropriate name.

Turn on PDF generation

We can turn on the PDF generation from the sales hub: navigate to the ‘App Settings’ area, then select ‘PDF Generation’ under ‘Sales Administration’. Since we created a Word Document related to the Opportunity entity, we want to make sure this entity is enabled.

In order to test to make sure you added all the correct fields to the word document, open an opportunity that has opportunity products. Click ‘Create PDF’ or ‘Email as PDF’ on the ribbon, then select the word document you just uploaded. Check your work and make changes if needed!

I hope you enjoyed this post! Be sure to check in again next week for a new topic or subscribe here to never miss another post!

Share this!

Comments are Closed