Document Template Manager XrmToolbox Plugin updates

Since my last post on my XrmToolbox plugin, My first XrmToolbox plugin – Document Template Manager, I’ve been doing some testing and identified areas of improvement and issues that need addressed. I’ve also heard of one issue that I wanted to highlight in this post.

Issue of note…

I am currently working on a project with a customer that relies heavily on Word Templates. While discussing the plugin, they mentioned issues with moving templates between environments that had not occurred to me. When you download a document template and CRM embeds the schema information into the document, it includes the Object Type Codes (OTC) in addition to the entity Schema Name. This information is used when traversing the entity record information and populating the template data. With system entities, OTC values remain static but with custom entities, they could, and usually do, change when importing customizations from one system to another.

So if you move templates for custom entities into a new environment, you will likely encounter errors.  Fortunately, the Document Template Mover tool should account for this issue.  Before transferring the template, the plugin will update the document source OTC codes with those found on the target environment. This involves opening the document and manipulating using the OpenXML libraries. It’s definitely worth taking a look at the code!

So this is definitely something to keep in mind when using this tool or simply developing templates that move between environments.

Some new features!

In my first release of the plug-in, I focused on downloading copies of document templates and updating the contents of a template. That seems to be working fine so far but seems a bit limited, namely forcing users to switch between the CRM web interface and the XrmToolbox. So I wanted to add some additional features that might be helpful while managing your document templates.

Upload multiple

The most significant bit of work came with the ability to upload multiple templates at one time. If you only work on a few templates, this may not be too big a deal. But my current customer has over 60 templates in their system (…hence my desire to create this plugin!) The updates to the upload functionality now allows you to create new templates from uploaded files, just as in the CRM user interface. Unlike the CRM web interface, this method will also update existing templates rather than creating new templates with duplicate names. if you upload a file with a name that matches an existing template name and type, the template on the server will be updated. For example, uploading Case Report.docx when an existing Microsoft Word document template named Case Report, the template will be updated. The tricky part with update comes with matching on the name because, as just stated, CRM will allow duplicate names.

When uploading a single file, you first select the template, then choose a file to upload, and the utility uses the unique ID of the selected item to match the template in CRM. In order to keep the user interface simple, I decided to match the file name to the template name in CRM when uploading instead of the template Id. This way, the user does not need to select templates, then for each selected template, choose the file that would update its content, and then upload. Because CRM allows duplicate template names, you could have two existing templates that match the name and template type. For example, what if I have two Microsoft Word templates named Case Report and I attempt to upload Case Report.docx? Which template should I choose to update? Essentially, I have no method of selecting the correct template to be updated.

Another issue could arise if a file is not of the correct type. For example, what if I attempted to upload a simple text file? CRM would simply not know what to do with the file on upload.

To account for unknown file types and ambiguous template names, I decided on a simple validation screen prior to performing the upload.  This dialog will present you a quick summary of what actions we will take on the list of selected files. You can review which uploaded files will result in a new document template, which will be updates, and which files will be ignored.

Upload Multiple Summary Dialog

Review actions taken with Upload Multiple

In this list, you can see the items are grouped by the different actions and a note provides some additional information.  In this case, I have a combination of Creates and Updates on both Microsoft Word and Excel templates while in the Ignore list, you can see that I had existing templates with duplicate names, Invoice Test Duplicate.docx, so the file was ignored.  Although it’s ignored during upload multiple, you can still select the individual template from the list and update it using Upload -> Upload Single.

I may revisit this matching in a later release, but for now, I believe that it adds helpful functionality for batch create and update when working on lots of templates.

Editing Templates

This is a relatively simple bit feature but I feel it can be a bit of a time saver.  You won’t need to switch between the web interface and the XrmToolbox just to update the document template Name and Description. Just select a template from the list and choose Other Actions -> Edit Template to view the edit dialog. You can also access this dialog via double click.

Edit Template

Edit Template Name and Description

This is another feature that I may revisit, such as providing inline edit within the main list view.

Additional Actions

Also added for convenience is the ability to perform actions of Activate, Deactivate, and Delete of one or more templates at a time. These are standard actions available from the CRM web user interface, but again, I feel it is a bit of a time saver having these features within the XrmToolbox. Note that, as with CRM, you cannot undo a delete!

And some minor tweaks

While working in the tool, I had a few little things that I’ve tried to address so that the plugin is a bit more user friendly. Below is a short list of some minor tweaks to the user interface that I found helpful.

  • Select All – in the main list, you can select Ctrl + A to select all items in the list
  • Sort by name – clicking any of the columns will sort the list by the template name. I’ll look into sorting by other columns in a later release
  • Instructions – With new features comes new instructions! You can double click to to expand and collapse the instructions to manage screen real estate
  • Zip archive folders – within the zip archive, I now place the files within folders first based on the template status and then by template type. For example, Activated\Microsoft Word\Invoice.docx

Squashing some bugs

Below is a short list of some of the issues that I’ve addressed with this update.  Fortunately, the list was short but these are issues that definitely needed fixing!

  • Saving a single template – If the document template file existed at the download location, it was not being saved correctly and could corrupt the saved template. Both a single file and the zip archivewill now save with a new file name, such as Invoice (1).docx
  • Downloads with duplicate template names – In the previous version, you would would receive an error stating that the key already exists. When adding files to the zip archive, the files will now be renamed using the same convention as downloading, such as Invoice.docxInvoice (1).docx, etc.

I hope that these updates address any issues users have faced and adds some helpful functionality.  I am also planning on moving the code to a github repository once I clean things up a bit.  I’ll update the plugin with the project URL once it’s published.

As always, feedback is welcome, including comments, suggestions, or bug reports!

0 Points