XrmToolbox plugin update – Document Template Manager

My first XrmToolbox plugin is the Document Template Manager, a plugin that allows users to create and update Microsoft Word and Excel templates. It has has come in handy over the last year since I first published. Just this past week, I was able to share the plugin with a new customer. This is a new contract and the solution includes over 60 Word Templates!

Finally adding this update!

One major feature missing from my Document Template Manager plugin was the ability to move Microsoft Word Document Templates between environments. This is because the dreaded Object Type Codes (OTC) are persisted within the XML schema embedded in the document.  So if you attempted to upload a Word Template exported from a development environment to a staging environment, the template would just not work.

Fortunately, a teammate on another project built a small utility that provides a solution. He used the OpenXml libraries to update the existing OTC in the document body with the OTC from the target environment prior to uploading. I was a bit leery of this approach as it seems risky to modify the document bits, so I did some reading as to other approaches. I did not need to look far:  MscrmTools.DocumentTemplatesMover toolbox plugin source code developed by the MscrmTools team takes a very similar approach. If those guys are confident with the solution, that’s good enough for me.

So I recreated the basic idea of the OpenXml approach in my plugin and it works well.  With this additional logic, the Document Template Manager plugin now allows you to upload Word Document templates downloaded from a different CRM instance. If the OTC map correctly, the user is not notified of any changes and the plugin works as it did before.  But I took the opportunity to add a few additional bits of logic to the plugin. First, before uploading the Word Document Template, the body is scanned for a valid Entity Type Name (ETN) within the document.  If this ETN not found, I don’t want to create or update using this file since it’s not a valid Word Document Template.

Upload single error - No ETN

The Document Template Manager plugin will also now check to see that the ETN from the Word Document being uploaded actually exists in the target environment.  If it does not, the file will not be uploaded because the template will not work. The goal here is to ensure that no junk is uploaded to your Dynamics CRM instance!

Upload multiple error - ETN not found

For now, this new functionality only applies to Word Document templates and not Excel Templates. Also, the the Document Template Manager plugin is not meant replace the Document Templates Mover plugin which allows you to connect between instances and move templates in bulk. The Document Templates Mover is a cool XrmToolbox plugin that operates really well on its own.

New tool is coming…

Although the Document Templates Mover plugin works great in most instances, I am again running into a DevOps issue with my new project. We need to remove the manual step of deploying the Document Templates to downstream environments and unfortunately, the XrmToolbox requires hands on operation.  Now that I have the updated code to ensure the Word Templates will work in downstream environments, I decided to port my code into a console application that will allow us to automate template deployment with these additional checks in place. I’ve worked out most of this application already so I will be deploying it later this week or early next when I’ve had some time to fully test.

Take the new plugin for a spin and as always, drop a line if you run into any issues or just have some cool suggestions.  Keep an eye out for the post about the Document Template Manager console push to Github this coming week!


Leave a Reply

Your email address will not be published. Required fields are marked *