I was involved with world template requirements for different entities. There were different things / hacks and bugs / problems I found during implementing Word Templates. I am trying to cover and list these things in this post. This might help any one else in understanding word templates and its issues.
1) Repeat Tag giving Null records in table
Repeat Tag is used for child entity records to list multiple records for parent records. For instance Invoice -> Invoice Detail. For repeat tag to work we have to use the same publisher prefix / same solution where we have created the child entity. Let me explain
Suppose you create custom child entity in solution "My Solution" having publisher with prefix "dev". Now this custom entity should have relation with Account Entity. Suppose we are capturing different Events data dynamically for the accounts.
Now if I made the relationship between Account and Events (custom entity) in default solution with prefix "new_" what will happen is the entity is created with prefix "dev_" but the relationship between account and envent is something like new_account_event_xxxxx.
This will lead word templates not to show the records for event entity. You will expect word tempates to populate / map records in table using repeating tag and even if there is data for that particular account in event entity in Dynamics, still when you generate word template for that account, word template will always give you null table and no events data will gen reflected in word file.
So to avoid null child records, must have to create the relationship from within the solution "My Solution" i.e. using prefix dev
2) Getting Updated / New fields for the entity
Suppose you have generated the word template from dynamics for Account entity and you have included all fields, relationships (1:N, N:1 & N:N) and you are using the template. Later there was new / existing requirement for which you need to add another field on account. But this new field is not available in your word template. In this scenario the solution is below
Download new template file from Dynamics
Remove .docx extension and changed it to zip
Export the zip
Now in customxml folder there will xml file(s), select the larger one.
Now in word template of your template "Select Add new part" in XML mapping in Custom XML Part:
Now you have another xml schema with same name, select the last one.
This will have updated / new fields and relationships within word file.
Below is same process with visual representation copied from (https://dynamicscrmpros.com/update-existing-word-templates-dynamics-365-crm/)
㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤ Ali Hamza Wadood | Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC) LinkedIn
1) Repeat Tag giving Null records in table
Repeat Tag is used for child entity records to list multiple records for parent records. For instance Invoice -> Invoice Detail. For repeat tag to work we have to use the same publisher prefix / same solution where we have created the child entity. Let me explain
Suppose you create custom child entity in solution "My Solution" having publisher with prefix "dev". Now this custom entity should have relation with Account Entity. Suppose we are capturing different Events data dynamically for the accounts.
Now if I made the relationship between Account and Events (custom entity) in default solution with prefix "new_" what will happen is the entity is created with prefix "dev_" but the relationship between account and envent is something like new_account_event_xxxxx.
This will lead word templates not to show the records for event entity. You will expect word tempates to populate / map records in table using repeating tag and even if there is data for that particular account in event entity in Dynamics, still when you generate word template for that account, word template will always give you null table and no events data will gen reflected in word file.
So to avoid null child records, must have to create the relationship from within the solution "My Solution" i.e. using prefix dev
2) Getting Updated / New fields for the entity
Suppose you have generated the word template from dynamics for Account entity and you have included all fields, relationships (1:N, N:1 & N:N) and you are using the template. Later there was new / existing requirement for which you need to add another field on account. But this new field is not available in your word template. In this scenario the solution is below
Download new template file from Dynamics
Remove .docx extension and changed it to zip
Export the zip
Now in customxml folder there will xml file(s), select the larger one.
Now in word template of your template "Select Add new part" in XML mapping in Custom XML Part:
Now you have another xml schema with same name, select the last one.
This will have updated / new fields and relationships within word file.
Below is same process with visual representation copied from (https://dynamicscrmpros.com/update-existing-word-templates-dynamics-365-crm/)
Add Updated
Fields / Entities (XML) to an existing template:
1. In your CRM environment, navigate to the
Templates area under Settings
2. Click on Document Templates
3. Click + New to
create a new Word Template
4. Select the primary entity you will be pulling
data from to use in the word template
1. If you’re updating an existing template, make
sure to choose the same primary entity as the exiting
2. If you’re creating a new word template for an
already created word document, select the necessary primary entity the word
template will be ran from.
5. If necessary, select any necessary
relationships that you’d like pull from the related entities of the primary
entity
6. Download the template and save on your local
PC
7. In Windows Explorer, navigate to the location
the template was saved
– I recommend creating a folder and putting the document in this folder. You’ll see why in the next couple of steps
– I recommend creating a folder and putting the document in this folder. You’ll see why in the next couple of steps
8. Rename the file and replace the file extension
from .docx to .zip
9. Right click on the file and use a compression
tool such as 7-Zip or WinZip to extract the file in the folder the file resides
in
10. You should now see the extracted files like
the example
11. Take note of this file location
12. On your PC, navigate to and open the word
template that needs updated
13. You will need to enable the Developer tab in
Word to bring in the Custom XML Part. If you have already enabled the Developer
tab in Word, skip to step 18. If you have not, continue with the below steps to
enable
14. In Word, navigate to File > Options >
Customize Ribbon.
15. Check the box next to Developer
16. Click ok
17. You should now see the Developer tab in the
ribbon
18. Click on the Developer tab > XML Mapping
Pane
19. The XML Mapping pane should appear
20. Click the drop down under Custom XML Part
21. Click Add new part…
22. Navigate to the file location from Step 10 and
open the customXml folder
23. Select the xml file. If
you have two, select the one that is larger in size and click open.
24. In the Custom XML Part drop down, you should
now see two parts that start with urn. One is the
original one from when the template was created, the other is the new one with
the latest fields and/or relationships.
25. Add the updates to the word template and save
the document
26. Upload the updated template to CRM and test
your updates
㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤ Ali Hamza Wadood | Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC) LinkedIn