Menu
Cart 0

Creating Document Attachment Templates Using Word

Posted by Author, Curator, Visually Impared Squirrel Literacy Advocate & Dynamics AX Technical Solution Professional (TSP) at Microsoft on

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…

  1. 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.
  2. 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.
  3. When you are sure that you have the query configured, click on the Close button to exit from the form.
  4. Now open up Word and create a new Blank Document.
  5. 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.
  6. 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.
  7. When you return to Word you will notice that the Field Browser is now shown on the left.
  8. Now start creating your template.
  9. 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.
  10. Keep on adding fields until you have all of the field data populated.
  11. Now save your document away.
  12. Now that you have finished creating the template, just close down the file.
  13. 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.
  14. This will open up the Upload Document dialog box. Click on the Browse button to open up the file browser.
  15. Then navigate to the template file that you just created and click on the Open button.
  16. When you return to the Upload Document dialog box, click on the OK button to upload the file to SharePoint.
  17. Once you have uploaded the file, just exit out of SharePoint.
  18. 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.
  19. When the Document Types maintenance form is displayed, click on the New button to create a new record.
  20. Then give your new record a Type code and also a Name.
  21. Change the Class to Template Library.
  22. And change the Group to Document.
  23. 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.
  24. 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.
  25. Then from the dropdown, select the Document Library where you stored the template.
  26. After you have done that, click on the Synchronize button.
  27. You should get an InfoLog box saying that one (or more) templates were synchronized.
  28. When you return to the Document Types form you will see the Template is now shown.
  29. All you need to do is click the Activate button to enable it.
  30. 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.
  31. When you click on it, Dynamics AX will diligently use the template that you created to create a new document instance.
  32. And then it will open up Word for you with the template and also the key fields populated for you.
  33. If you want to update the template for everyone, then just return to the original Word template, update it and then save it.
  34. Then return to the SharePoint library and re-upload the template file (overwriting the previous version).
  35. And then open up your Document Types, find the template library and click the Synchronize button again.
  36. Dynamics AX will find the document for you and update the template it references.
  37. If you go back to your main form and create another document from the template…
  38. Then it will use the new version of the template that you just uploaded.
  39. 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.
  40. 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.

Rock on!

For more information and to download the full walkthrough, click the link below:
http://www.dynamicsaxcompanions.com/Tips-And-Tricks/Tips-Tricks-Archive/Creating-Document-Attachment-Templates-Using-Word




Share this post



← Older Post Newer Post →


Leave a comment

Please note, comments must be approved before they are published.