Finding Document Templates for Entities in Dynamics 365 – Part 3: Adding a Custom Button

In our previous post, we discussed a Dynamics 365 client had a need to add a new button to the to an entity’s ribbon that allowed for the client to:

  • open a popup window,
  • select a document template designated for the entity,
  • generate a document based on the template, and
  • add it to the the entity’s annotations

It was focused on publishing the newly created page to Dynamics CRM. In this post, we will be reviewing how to create a button on the entity’s form to open our newly created control.

Adding Your Document Templates Custom Button

Now that we have all the code uploaded to Dyanmics CRM, it is time to add it to our entity. To do this, we will create a custom button on the entity’s ribbon. This custom button will be responsible for opening the pop-up window that we created in the previous post.

The only requirement that we have for this button is that it should only be displayed for records that have been created. That is to say, it should not appear on the entity’s create form.

To add the custom button, we will be using the Ribbon Workbench, a plugin for the XRM Toolbox. In Dynamics CRM, ribbon data is represented by some rather large XML files that can be a headache to read for those who have not worked with them before. The Ribbon Workbench presents developers with a nice GUI for editing the ribbon.

The entity we will be adding it to will be the Incident (Case) entity. We’ve chosen this one because it comes out of the box with document templates to work with, obviating the need to create some for testing. This control, however, can be applied to other entity types as well.

Creating your Solution

Before we can publish our Document Templates control customizations to the ribbon, we will have to create a solution to store those customizations.

1. In Dynamics 365, open the solution window by clicking Settings:Solutions

2. Click the New button to create a new solution

3. Create the custom solution with your data

4. Choose Entities from the menu on the left. Click Add Existing and choose the Incident entity

5. Add the web resources that we’ve already uploaded by clicking Web Resources on the menu on the left. Then click Add Existing.

To make them easier to find, sort them by State. The web resources we previously uploaded should be unmanaged.

6. Click Save and then Publish All Customizations. And that should be it. Your solution is now ready to customize.

Connecting The Ribbon Workbench to your Organization

The people at the XrmToolBox site have created excellent documentation on how to connect to your organization. Head over there to read up on how to connect to your organization.

Updating the Ribbon

In this section, we’ll cover how to add a button to an entity form that will open up our custom document templates control. As we said previously, we will be using the Incident entity. Once you’ve connected the ribbon work bench to your organization and solution:

1. Drag a new button on to the form command bar

2. Fill out the button’s properties. Below are the settings that we used. You won’t be able to set the command until after the next step.

3. In the Solution Elements pane, click the + next to the Display Rules label.

4. Create a display rule with the following settings. This display rule makes it so the command is only available when the Case is existing; we cannot execute it on the New Case form.

5. In the Solution Elements pane, click the + next to the Commands label

6. Create a command with the following settings. Note the new_ before our file. Yours will be whatever the prefix is for your file. Be sure to include the previously created display rule

6. Go back and set the command on the button settings.

With that, you’re ready to publish your customizations to the CRM. Simply click the Publish button at the top and you’re all set!

Testing Your Document Templates Custom Button

Now, you should simply be able to open up a case, see your button, and click on it. When you click on it, you should see the control that we had previously created. Using this technique, you should be able to make infinitely customizable controls for your organization.


Dynamics Controls for your Organization

Code Vanguard offers a collection of premium Dynamics 365 controls for your organization. Built on top of the Microsoft’s Fabric UI and Google’s Material UI, Dynamics UI is a set of responsive UI elements for Dynamics that looks good on any device! Check out our Dynamics UI page to learn more.


Check out some of our other posts about Dynamics CRM!

Tags:
James Stephens About the author

James is the founder of Code Vanguard and one of its developers. He is an applied mathematician turned computer programming. His focuses are on security, DevOps, automation, and Microsoft Azure.

No Comments

Post a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.