Posted by Paul Haag
Document (Word or Excel) templates in Dynamics 365 allow you to merge CRM data into a pre-formatted document. Details on that process can be found here: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/using-word-templates-dynamics-365. Unfortunately, once you create the template, there’s no straightforward way to download the original template again from Dynamics 365. So, if you decide you want to make a change and can’t find the original document, you must go through the exercise of remapping all the Dynamics 365 data fields. With the web API and a couple of online tools, though, you can get back up and running. |
1. In a browser (not Internet Explorer), run the URL you will need to download the template (replace the highlighted bits with the correct values for your CRM system and template): https://yourtenant.crm.dynamics.com/api/data/v8.1/documenttemplates?$select=name,content&$filter=name eq 'Your Template Name'
2. Take the result and make it a little easier to read by copying and pasting it into a JSON formatter (like JSON Pretty Print).
3. This will result in a very long bit of text, but the part you want is between the quotes for the content (example content value highlighted below): {
"@odata.context": "https:\/\/yourtenant.crm.dynamics.com\/api\/data\/v9.0\/$metadata#documenttemplates(name,content)",
"value": [
{
"name": "Your Template Name",
"content": "UEsDBBQABgAIAAAAIQAr[content truncated for brevity]==",
"documenttemplateid": "31418de7-0c19-e911-a97e-000d3a10877d"
}
]
}
4. The “content” is the Word or Excel file, but encoded in a special web-friendly format called Base 64. This can be transformed back into the original file by using a decoder service like the one available here: https://www.freeformatter.com/base64-encoder.html
2. Take the result and make it a little easier to read by copying and pasting it into a JSON formatter (like JSON Pretty Print).
3. This will result in a very long bit of text, but the part you want is between the quotes for the content (example content value highlighted below): {
"@odata.context": "https:\/\/yourtenant.crm.dynamics.com\/api\/data\/v9.0\/$metadata#documenttemplates(name,content)",
"value": [
{
"name": "Your Template Name",
"content": "UEsDBBQABgAIAAAAIQAr[content truncated for brevity]==",
"documenttemplateid": "31418de7-0c19-e911-a97e-000d3a10877d"
}
]
}
4. The “content” is the Word or Excel file, but encoded in a special web-friendly format called Base 64. This can be transformed back into the original file by using a decoder service like the one available here: https://www.freeformatter.com/base64-encoder.html
- Paste the content value in the box to decode.
- Click the DECODE AND DOWNLOAD button.
- When saving the file, change the extension to .docx or .xlsx (depending on if it is a Word or Excel template)
- Open the downloaded file.