2 - Customising Standard Ribbons

In Chapter 1, we covered basic addition of new buttons to the ribbon. In this chapter we'll talk about changing standard controls and commands of the out of the box ribbons or managed solutions that you may have installed.

In later chapters we'll talk about how managed solutions are added to the ribbon, but at this stage it's worth knowing that when you install a Managed Solution, any ribbon customisations essentially are merged into the out of the box customisations and can be treated as such. You might have noticed that when you import a managed solution into Dynamics CRM you have the option to overwrite any customisations that have been made - this applies to customisations of ribbon elements too.

This chapter contains the following sections:

  1. Customising User Interface Elements
  2. UnCustomising Commands
  3. Using Core Enable and Display Rules
  4. Moving Buttons
  5. Customising Sections

Customising User Interface Elements

Customisations to standard ribbon elements can be applied at different levels:

  1. Menu Items within a Split/Fly out button - Allows customisation of:
    1. Menu Item name
    2. Menu Item command
    3. Menu Item icons
  2. Menu Section within a Split/Flyout button - Allows customisation of:
    1. Section Name
    2. Position of Menu Items within that section
  3. Individual Buttons/Controls - Allows customisation of:
    1. All of the above
    2. Button Name
    3. Button Command(s) being called
    4. Icons of buttons
  4. Ribbon Groups - Allows customisation of:
    1. All of the above at the button level
    2. Changing the name of the group
    3. Changing the layout template applied to group
    4. The sequence of buttons within that group (drag-and-drop)
    5. The scaling of the group when the ribbon is resized.
  5. Ribbon Tabs - The whole tab is customised so that any element maybe changed. This includes all of the above, but also:
    1. All of the above at the button and group level.
    2. The position of groups within the tab
    3. The name of the tab
    4. The rules for determining when the tab is displayed
    5. The scaling of all the groups within the tab

To customise at each of these levels using the Ribbon Workbench, simply use the right click menu on the ribbon element (tab, group or button) and select 'Customise'. Once customised a red tick will appear and it will be included in the Ribbon Elements Panel tree-view. Once a specific level is customised it will also customise all lower levels - so if you customise a tab, all groups and buttons included within that tab will also be customised. To avoid conflicting customisations you cannot customise a higher level once you've customised a lower level - so if you've customised a button, you'll not be able to customise a group or tab that it is included within.

Once you've customised a standard button, group or tab, it essentially acts as though you had dragged it onto your ribbon as a new element - the only difference is that it will be overriding the standard behavior when the ribbons are merged together.

Customising Commands

As well as the user interface elements (menus, buttons, groups & tabs), the Ribbon Workbench allows you to customise commands that are called by buttons whilst not customising the button it's self. This is useful if multiple buttons call the same command, or where you want to change the behavior of the button, but don't want to change the look.

You may have notice that when a button was customised earlier, it contained a property named 'CommandCore' - this is a free text field that points to a 'Core' command that is outside of the solution. If at any point you need to override the behavior of a button's command you have two options:

  1. Create a new Command in the Solution and selecting this command in the Buttons 'Command' Property. This option is the same as we performed in Chapter 1.
  2. Customise the Button's command and change the standard behavior. This is the approach that is described below.

You will recall that a Command is made up of:

  1. Actions - used to define what will happen when the command is called (e.g. JavaScript function called or web page opened)
  2. Display Rules - used to define when a button that calls this command will be displayed
  3. Enable Rules - used to define when a button that calls this command will be enabled

The interesting part of customising commands is that although you can't alter the visual elements of buttons that call it, you can alter when those buttons are enabled or hidden.

Customising a Command is achieved by selecting the standard button that calls it, using the right click menu and selecting 'Customise Command'. Once customised, the command will appear in the Solution Elements in the same way as it would if you had added a new command as we did in Chapter 1.

Now that the command is customised you can change or add to the command actions in much the same way as you would if it was a new command. If you customise the command on another button that calls the same command, nothing will happen since it is already customised. Scott Sewell of CustomerEffective has a good blog posting that shows how commands can be customised.

Uncustomising Commands

If at any point you no longer want to customise a command, you can simply use the right click command and select 'Delete'. This will remove it from the Solution Elements in the same way it would when you had created a new Command. The difference being that the command will now revert back to the core definition upon the next publish rather than removing it all together.

Using 'Core' Display and Enable Rules

In the same way as a button can point to a 'Core' command without it being included in the solution, a Command can also point to a 'Core' Enable or Display Rule such as the built-in 'Mscrm.Enabled' rule. When you customise a command, all of the Enable and Display Rules it uses will initially also be customised. These can then be 'Uncustomised' by changing the 'IsCore' property to 'False' if you don't need to change the behavior of these rules.

Moving on up...

A common requirement in Microsoft Dynamics CRM projects is to hide or move buttons around on the ribbon. The Ribbon Workbench for CRM 2011 allows you easily do this with very little fuss.

Moving a Button within a group

In order to move a button within a group you need to change sequence of the button with the group. You might first think that this could be done simply by customising the button and then changing the sequence, however this does not seem to reliably work.

The most effective way is either customise the entire group and move the buttons around, or to hide the core button and create a custom copy of the button in the new desired position.

Moving a button using 'Customise Group'

1) Select the group you wish to move a button within and use the right click menu to select 'customise group'

2) Drag the button you wish to move into to it's new location

3) Publish the solution

Moving a button by hiding the core and creating a copy.

1) Customise the button you wish to move by selecting 'Customise Button' from the right click menu.

2) Drag the button to the new location. The Ribbon Workbench will conveniently hide the old button and create a copy of it for the new location.

3) You can also move buttons a completely different group or tab using this method so it is the method that is recommended. To move to a different tab, simply drop the button on the tab label and the button will be placed at the start of that tab. You are then free to drag it to the new location.

Customisation of Sections

 As with moving buttons, menu items can also be re-arranged by customising the parent button.

1) Select the Anchor or Fly-out button you would like to change the order of menu items within.

2) Click on the button to show its menu, and then select the section that contains the button you would like to move.

3) Select the item you want to move and use the right click menu 'Move Up' or 'Move Down'

Since the section has been customised, you may also add new menu items using the 'Add New Menu Item' on the right click menu of the menu section. If you don't want to move the menu item, you can simple customise the item to change it's look or the command that it calls.

Conclusion

In this chapter we have learnt how to change the behavior of standard ribbon elements by customising them, and then this is cascading operation that will also customise any child-elements. It is important to select the correct level so that you only customise what you need to. It is not a good idea to customise the whole tab if you simply want to change the label of  a single button.

Experiment with customising commands, buttons, groups, tabs and menu sections so that you can quickly change the ribbon when you need to.

Feedback and Knowledge Base