When it comes to guids, take your lead from the boy band NSYNC #HoskWisdom
I had a problem with Document templates, guids and getting out of sync between environments. When guids are out of sync, manual work is needed every time you deploy, this can add up to a lot time of the course of a project.
Document Templates are an impressive feature that allows you to create Word or Excel templates that work in a similar way to mail merge. Once you create the word template once, users can use them to generate a word document using values from Dynamics. Compared to SSRS reports these are lightening fast and anyone can create them.
To learn more, read these posts
- How to Create a Microsoft Word Template in Microsoft Dynamics 365
- MB 210: Microsoft Dynamics 365 for Sales — Word Templates
- Create and manage Word templates in Dynamics 365 Sales Professional
Sounds great, what’s the catch
It’s a powerful time-saving feature but Microsoft forgot to create a method to move these documents between environments. Microsoft want Dynamics 365 to create enterprise solutions but don’t provide the tools to do. To have functionality that you have to create manually isn’t a suitable solution.
Document templates are either Word or Excel document which you upload to Dynamics 365. When you upload the document it create a record in Dynamics with the word document attached.
Where you have records, you have guids and where you have guids, you need to keep those in sync between environments.
Microsoft would like you to manually create the document template in each environment. Doing this will create a different guid for the document template in each environment.
Why is this a problem?
When you use a document template in a workflow, it uses the guid of the document template record.
You might be wondering why you would use a document template in a workflow but the is a useful action created by Microsoft that allows you to create a document using a document template via a workflow
We used this but the problem is when we move the workflow from Dev to QA the workflows are deactivated and you need to open the workflow and lookup the correct document template in the environment and then publish. This can be a drain of time if you have to do it after every deployment in every environment.
I do not like doing anything on deployments manually, particularly boring workflow repointing tasks.
I created a document template called Hosk Test, you can see it has different guids in DEV and QA.
Hosk Test — DEV
Hosk Test— QA — Manually created
What’s the solution
You can create a console app written in C# and create, update document templates — Document template SDK, if you have an ALM process it’s worth the time to create a tool to move them between environments.
The tool allows you to select a source and target environment and then move the templates between environments.
It does a few things which are neat
- Keeps the same guid between environments
- Converts the object type code between environments
- Works easily and quickly
It would have been great if it was a command line and then we could add it to a build task and include it into the build but a manual step of moving document templates isn’t too bad because Document templates don’t change very often.
The code is open source if you want to see how the magic is done
picture from here