In the perfect world, all documents and reports that are created out of Dynamics AX should be created within Reporting Services, sometimes don’t have the time or the resources available to create the reports, so you end up resorting to using other tools like Word or Excel to create quick and dirty versions. I’m not judging you all, because you have to do what you have to do, but if you do use Office as a reporting tool, then there is a feature within Dynamics AX that allows you to save your Word documents as templates and then link data directly from the system into the document, and also automatically save the document that is created as a document attachment. It gives you the best of both worlds – reporting on a shoe string, and also control over the documents.
It’s like having your own personal printing press.
How To Do It…
- Before we start you need to make sure that you have some data that Word is able to read. To do this, click on the Document Data Sources menu item within the Document Management folder of the Setup group within the Organization Administration area page.
- You need to make sure that you have a Query Reference or a Custom Query defined for the main header table of the record that you are going to create the document template for. In this case we are creating a document template for the Sales Quotations so we have a Query Reference defined on the SalesQuotationTable table.
- When you are sure that you have the query configured, click on the Close button to exit from the form.
- Now open up Word and create a new Blank Document.
- When the blank document is created, click on the Dynamics AX tab within the ribbon bar and then click on the Add Data button within the Design group.
- This will open up the Add Data dialog box showing you all of the registered Query References and Custom Queries. Select the main Data Source that you want to use for the document template and then click the OK button.
- When you return to Word you will notice that the Field Browser is now shown on the left.
- Now start creating your template.
- If you want to embed any field values in the word document then you can just drag and drop them from the Field Explorer over to the document.
- Keep on adding fields until you have all of the field data populated.
- Now save your document away.
- Now that you have finished creating the template, just close down the file.
- Now we need to save the document to a SharePoint Document Library. If you don’t have one yet, just create a blank Document Library and then note down the URL it and then click on the Add Document link within the library.
- This will open up the Upload Document dialog box. Click on the Browse button to open up the file browser.
- Then navigate to the template file that you just created and click on the Open button.
- When you return to the Upload Document dialog box, click on the OK button to upload the file to SharePoint.
- Once you have uploaded the file, just exit out of SharePoint.
- Now we need to create a Template document type that we will use to synchronize with SharePoint and then use to reference all of our document templates. To do this, click on the Document Types menu item within the Document Management folder of the Setup group within the Organization Administration area page.
- When the Document Types maintenance form is displayed, click on the New button to create a new record.
- Then give your new record a Type code and also a Name.
- Change the Class to Template Library.
- And change the Group to Document.
- Then click on the folder button to the right of the Archive Directory field and point the Browser to a working directory where you can store all of the template files and then click the OK button.
- You may have noticed that when you selected the Template Library Class a new tab displayed in the bottom of the form. Paste in the site URL (without the document library) for the SharePoint Document Library where you uploaded the template into the SharePoint Site field.
- Then from the dropdown, select the Document Library where you stored the template.
- After you have done that, click on the Synchronize button.
- You should get an InfoLog box saying that one (or more) templates were synchronized.
- When you return to the Document Types form you will see the Template is now shown.
- All you need to do is click the Activate button to enable it.
- Now when you go to your main form (the Sales Quotations in this case) and click on the Generate From Template button, the Word template will be shown to you.
- When you click on it, Dynamics AX will diligently use the template that you created to create a new document instance.
- And then it will open up Word for you with the template and also the key fields populated for you.
- If you want to update the template for everyone, then just return to the original Word template, update it and then save it.
- Then return to the SharePoint library and re-upload the template file (overwriting the previous version).
- And then open up your Document Types, find the template library and click the Synchronize button again.
- Dynamics AX will find the document for you and update the template it references.
- If you go back to your main form and create another document from the template…
- Then it will use the new version of the template that you just uploaded.
- Another benefit of this feature is that all of the documents that you create are tracked and saved as attachments against the record that you created them from. To see them, just click on the Attachments button in the ribbon bar.
- You will see all of the versions of the document that were created. And to see the document itself, just click on the Open button in the menu bar.
This will open up the Word document that was created by the template.
For more information and to download the full walkthrough, click the link below:
Share this post