Microsoft Dynamics CRM 2011– Adding and Removing Buttons from the Ribbon
This tutorial will show you how to add and remove buttons to the ribbon in CRM 2011.
There are three different places you can add buttons to on the CRM Ribbon. They are the entities grid view (HompageGrid), the form (Form), and the in-line grid inside of another form or dashboard (SubGrid).
Adding a Button to the Ribbon
Adding a button has two parts, the first part is finding the control which we want to add the button to, and the second part is modifying the customization.xml file to add the button.
Part 1: Find the Control
Download and install the latest CRM 2011 SDK. (http://www.microsoft.com/downloads/en/details.aspx?familyid=420f0f05-c226-4194-b7e1-f23ceaa83b69)
Open the following Visual Studio solution from the SDK: $\sdk\samplecode\cs\client\ribbon\exportribbonxml\exportribbonxml.sln
Run the program, connect to the necessary CRM organization, and generate the files. Note, if you are connecting to an online organization, the connection URL will be crm.dynamics.com
Your command window will look similar to the following when it is complete:
Open up the generated xml file from $\sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml\<entity_name>Ribbon.xml
From here you can find the different tabs for the HomepageGrid, Form, and SubGrid. In my case, I have opened the .xml file for tallan_ribbontest. Note that you cannot modify the ribbon by changing this file.
Now you have to locate the necessary control for the tab that you want to add or remove a button to.
In this example I am going to add a button to the Data group on the Main tab of the Form.
The control for this is as follows:
Part 2: Modifying the customization.xml file
Now that we have the control, we can add the button to our Ribbon.
Create a CRM Solution with the single entity whose ribbon you want to customize.
Export it as unmanaged and open the customizations.xml file. You can use any xml editor to modify it. In my case I am using Visual Studio.
Search for <RibbonDiffXml>. This is where we will be making most of our modifications.
Under the <RibbonDiffXml> node, we will modify the <CustomActions /> node to add the button.
Replace it with the following code:
LabelText=”Open Web Site”
The Location tag is defined as the Control that we found above, followed by “._children“. This can be changed based on any control tag.
If you have your own images, you can add them as a web resource and reference them as follows:
Be sure not to forget to close the CustomActions node.
<Url Address=”http://www.tallan.com />
This will link to the URL http://www.tallan.com
<CrmParameter Value=”SelectedControlSelectedItemReferences” />
<StringParameter Value=”StringParameter” />
After we have added the button and the command, save the customizations.xml file, add it back to your solution.zip file, and import it into your organization.
Once your customizations are published, you will be able to see the new button in the ribbon.
Removing a Button from the Ribbon:
Hiding a ribbon button is actually easier than adding a button. Removing a button has two parts. The first part is finding the Button Id that you want to hide, and the second part is adding the action to hide that button.
Part 1: Find the Button Id to remove
In this example we are going to hide the “Save” Button from the Form.
First we need to go back to the file that was generated from the SDK solution (<entity_name>Ribbon.xml)
Find the button that you want to remove.
We can see that this is the correct button because it is under the Form, it is the MainTab, it is under the Groups node instead of the Scaling node, and the button ID has the correct description.
Part 2: Remove the button using customization.xml
Now we go back to the customizations.xml file from above, and we add the following line to the CustomActions section.
<HideCustomAction Location=”Mscrm.Form.tallan_ribbontest.Save” HideActionId=”Mscrm.Form.tallan_ribbontest.Save.HideAction” />
Save the customization.xml file, add it back to your solution.zip file, import it back into the system, and publish the customizations.
The form will now look as follows:
It is possible to add the XML schemas for the ribbon to have some intellisense while making modifications. In Visual Studio, from the XML menu click “Schemas…” then “Add…”. After that you can add the following Schemas:
These schemas are located in the SDK in the following location: $\sdk\schemas