Add a button in Dynamics 365 CRM with Ribbon Workbench
A common task as a Dynamics 365 CRM consultant involves adding a button to trigger specific actions or open forms. You may also need to modify or hide some existing buttons, and to achieve this you will most likely use a singe tool: The Ribbon Workbench
In this example I’ll show you how, using XRM Toolbox (you can find our introduction to this tool here), this can be easily achieved.
Installing the Ribbon Workbench for Dynamics 365 CRM
The Ribbon Workbench is a very powerful tool developed by Microsoft MVP Scott Durow. It allows you to create custom buttons and actions but also edit the “Out of the Box” ones. In the following example we will be looking at how to create a simple button to execute code.
There are two ways to use the tool and in the end the interface is the same, yet, I find it easier to have all my tools in one place and easily manage updates which is why I prefer to use the plugin for XRM Toolbox. You may also download a solution for your CRM and Install it if you prefer.
Let’s start by downloading the plugin.
- Open XRM Toolbox and go to “Tools ==> Plugin Store”.
- Search for “Ribbon” and download the plugin
- Connect to a Dynamics 365 development environment and start creating!
Getting ready to use the tool
You have downloaded the tool, now it’s time to prepare a solution to work with it! I personally prefer to create a solution with one entity inside named “EntityNameRibbon”, example: “CustomerAssetRibbon“. The reasons behind this choice are the following:
- The more entities you have in a solution, the slower it is to Publish, meaning you’ll waste more time before testing your code and fixing issues.
- There is a limit to the number of entities you can have in a solution before Publishing plain and simply stops working.
- Having a single entity or a couple of related entities like “incident” and “msdyn_workorders” allow to better manage the scripts, images and release of new features.
- You may be working on multiple buttons in different entities and only want to release code for a single one of them.
Inside of this solution I will place the following:
- An Entity without any resources (you will need to uncheck the top right box when adding an Entity to your solution).
- My scripts and icons (16×16 and 32×32) with a specific naming convention.
Create a button with the Ribbon Workbench for Dynamics 365 CRM
Understanding the User Interface
- The first row controls the buttons shown in the entity views.
- The second row controls the buttons available when selecting a record in a SubGrid (example when you select contact in a sub grid view showing all of the contacts of an Account).
- The third and last row controls the buttons available when looking at a specific record from the entity.
- For a detailed explanation regarding this command bar I can refer you to the Microsoft documentation.
- This controls the different types of buttons you can implement, just drag & drop one to the top three rows to create a button (careful, if you publish a solution with a button it is quite difficult to delete afterwards).
- Select an Entity (if you have more than one in the solution).
- Allows you to configure the button(s).
Creating your first button
Create a Command:
Start with creating a command. Click on the “+” next to the “COMMANDS” title to create a blank one.
- Add Parameter, just bellow #2, this allows you to pass a parameter to the executed function. There are multiple types of parameters:
- String/Integer/Decimal/Boolean ==> Pretty standard, you may want to send a string containing the RECID of a Workflow you wish to run or a text used in the script.
- CRM Parameter ==> Allows you to pass page data as a parameter (this is used when passing the RecId of one or multiple subgrid items). The complete documentation can be found here.
Create, configure and position the button:
Drag & drop the button in one of the top three rows. This will create an entry in the “BUTTONS” section.
- The newly created button.
- The existing commands.
- The selected command.
- Command Core is used to reference a Command by ID when the command is defined in the managed layer rather than the solutions unmanaged layer. If you can’t see your command in the drop down menu, type it here. As a rule I always type the command here even though I find it in the drop down since I’ve seen it done by other consultants and it doesn’t hurt to do so.
These are the essentials. You should then enter a Label, Alt, Tool Tip Title, Tool Tip Description (It’s not mandatory to enter fill in anything besides of the Label but I’ve already encountered errors which where fixed by putting text in the tool tip so I always try to put something in it). As for the 16×16 and 32×32 images, I either reuse the ones available in CRM or find new ones in google which I then add as a web resource.
And that’s it! All you need to do now, is Publish the solution, test and deploy! Remember that if the solution is too long to compile and you are having issues with your script, you can always trigger it in a form “On Load” debug it and once everything is working smoothly, attach it to a button.
Thanks for reading, if you liked this content hit the like button and feel free to leave a comment!