How To – Series 7: How To override(Enable, Disable, Show, Hide, Custom Logic) Out of the Box HomePageGrid ribbon elements – CRM 2011

Hope my earlier posts on Ribbon elements helps you. In this post we will see how to Enable/Disable Out of the Box ribbon elements in Dynamics CRM 2011. After going through the SDK, it seems there is no direct solution to override existing <CommandDefinition>. However, the documention says using <CustomAction> we can Add or Replace items in the ribbon. It gives me an idea to replace existing OOB(Out of the Box) ribbon item with Custom ribbon item and define our own <CommandDefinition> for that. At the same time we can also go with the OOB <CommandDefinition>. Lets see how we can do that stuff.

Lets consider “Edit” ribbon item on the “Account” entity “HomePageGrid”. I want to disable this “Edit” button when user selects more than one record in the sub grid(i.e I don’t want “Bulk Edit” feature for Account records). The same can be achieved with security roles. However, for the sake of simplicity and to focus more on how we can override <EnableRules>, <DisplayRules> and <Actions> for an OOB item I have considered this scenario.

 

Step 1:

 

Open “accounribbon.xml” file from the “sdksamplecodecsclientribbonexportribbonxmlexportedribbonxml” location in the CRM 2011 SDK.

 

Below is the definition for “Edit” button

 

<Button Id=”Mscrm.HomepageGrid.account.Edit” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipDescription=”$Resources(EntityDisplayName):Ribbon.Tooltip.Edit” Command=”Mscrm.EditSelectedRecord” Sequence=”20″ LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Image16by16=”/_imgs/ribbon/Edit_16.png” Image32by32=”/_imgs/ribbon/edit32.png” TemplateAlias=”o1″ />

 

 

Below is the <CommandDefinition> for “Edit” button.

 

 

<CommandDefinition Id=”Mscrm.EditSelectedRecord”>

 

        <EnableRules>

 

          <EnableRule Id=”Mscrm.CheckBulkEditSupportForEntity” />

 

          <EnableRule Id=”Mscrm.VisualizationPaneNotMaximized” />

 

        </EnableRules>

 

        <DisplayRules>

 

          <DisplayRule Id=”Mscrm.BulkEditPrivilege” />

 

          <DisplayRule Id=”Mscrm.WriteSelectedEntityPermission” />

 

        </DisplayRules>

 

        <Actions>

 

          <JavaScriptFunction FunctionName=”Mscrm.GridRibbonActions.bulkEdit” Library=”/_static/_common/scripts/RibbonActions.js”>

 

            <CrmParameter Value=”SelectedControl” />

 

            <CrmParameter Value=”SelectedControlSelectedItemReferences” />

 

            <CrmParameter Value=”SelectedEntityTypeCode” />

 

          </JavaScriptFunction>

 

        </Actions>

 

      </CommandDefinition>

 

 

Copy both of the definitions and we gonna use them in the next steps.

 

Step 2:

 

Add “Account” entity to a solution. Export it. Open “Customizations.xml” file.

 

Go to <EnableRules> section and add following <EnableRule> which will return “true” when only one item is selected in the sub grid.

 

 

   <EnableRule Id=”Sample.account.grid.OnSelection.EnableRule”>

 

              <SelectionCountRule AppliesTo=”SelectedEntity” Maximum=”1″ Minimum=”1″/>

 

            </EnableRule>

 

 

Step 3:

 

 

Go to <CommandDefinitions> section and add copied <CommandDefintion> form the Step1. Rename “Id” value to “Sample.account.grid.DisableExisting.Command”

 

<CommandDefinition Id=”Mscrm.EditSelectedRecord”>

 

        <EnableRules>

 

          <EnableRule Id=”Mscrm.CheckBulkEditSupportForEntity” />

 

          <EnableRule Id=”Mscrm.VisualizationPaneNotMaximized” />

 

        </EnableRules>

 

        <DisplayRules>

 

          <DisplayRule Id=”Mscrm.BulkEditPrivilege” />

 

          <DisplayRule Id=”Mscrm.WriteSelectedEntityPermission” />

 

        </DisplayRules>

 

        <Actions>

 

          <JavaScriptFunction FunctionName=”Mscrm.GridRibbonActions.bulkEdit” Library=”/_static/_common/scripts/RibbonActions.js”>

 

            <CrmParameter Value=”SelectedControl” />

 

            <CrmParameter Value=”SelectedControlSelectedItemReferences” />

 

            <CrmParameter Value=”SelectedEntityTypeCode” />

 

          </JavaScriptFunction>

 

        </Actions>

 

      </CommandDefinition>

 

 

Add    <EnableRule Id=”Sample.account.grid.OnSelection.EnableRule”/> to the <EnableRules> section.

 

 

<CommandDefinition Id=”Mscrm.EditSelectedRecord”>

 

        <EnableRules>

 

          <EnableRule Id=”Mscrm.CheckBulkEditSupportForEntity” />

 

          <EnableRule Id=”Mscrm.VisualizationPaneNotMaximized” />

 

          <EnableRule Id=”Sample.account.grid.OnSelection.EnableRule”/>

 

        </EnableRules>

 

        <DisplayRules>

 

          <DisplayRule Id=”Mscrm.BulkEditPrivilege” />

 

          <DisplayRule Id=”Mscrm.WriteSelectedEntityPermission” />

 

        </DisplayRules>

 

        <Actions>

 

          <JavaScriptFunction FunctionName=”Mscrm.GridRibbonActions.bulkEdit” Library=”/_static/_common/scripts/RibbonActions.js”>

 

            <CrmParameter Value=”SelectedControl” />

 

            <CrmParameter Value=”SelectedControlSelectedItemReferences” />

 

            <CrmParameter Value=”SelectedEntityTypeCode” />

 

          </JavaScriptFunction>

 

        </Actions>

 

      </CommandDefinition>

 

 

 

Step 4:

 

 

Add following <CustomAction> to the <CustomActions> section:

 

 

          <CustomAction Id=”Sample.account.grid.DisableExisting.CustomAction” Location=”Mscrm.HomepageGrid.account.Edit” Sequence=”21″>

 

            <CommandUIDefinition>

 

              <Button Id=”Mscrm.HomepageGrid.account.Edit” Command=”Sample.account.grid.DisableExisting.Command” LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipDescription=”$Resources(EntityDisplayName):Ribbon.Tooltip.Edit” TemplateAlias=”o1″ Image16by16=”$webresource:new_/icons/TIcon16x16.png” Image32by32=”$webresource:new_/icons/TIcon32x32.png” />

 

            </CommandUIDefinition>

 

          </CustomAction>

 

 

Here we need to carefully observe what we have done to replace existing “Edit” button with our own Custom Button.

 

<CustomAction Id=”Sample.account.grid.DisableExisting.CustomAction” Location=”Mscrm.HomepageGrid.account.Edit” Sequence=”21″>

 

 

Here I have given  unique id for the <CustomAction> and for the “Location” attribute I have placed “Id” of the OOB “Edit” button only. I haven’t kept “._children”. This makes all the difference…

 

 

<Button Id=”Mscrm.HomepageGrid.account.Edit” Command=”Sample.account.grid.DisableExisting.Command” LabelText=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” Alt=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipTitle=”$Resources:Ribbon.HomepageGrid.MainTab.Management.Edit” ToolTipDescription=”$Resources(EntityDisplayName):Ribbon.Tooltip.Edit” TemplateAlias=”o1″ Image16by16=”$webresource:new_/icons/TIcon16x16.png” Image32by32=”$webresource:new_/icons/TIcon32x32.png” />

 

 

Here, I have given OOB “Edit” button “Id” as the “Id” for the new item. Do remember that, “Id” value in the <Button> should be same as “Id” value in the <CustomAction>. In other words the new Ribbon Item should have same “Id” as the OOB item.

 

For the “Command” attribute I am planning to use OOB Command that has been defined for the “Edit” item. I am planning to use OOB features and in addition to that I am planning to have my own <EnableRules>, <DisplayRules> and <Actions> rules. Feel free to use your own Command if you require to.

 

For remaining attributes also I wish to go with OOB except for the Images. Here I want to show images from my web resource.

 

Now, Import the solution with these changes to your system. Below is the result:

When no recod is selected:

When One record is selected:
When multiple records are selected
In this way we can override OOB behaviors and visualizations for OOB ribbon elements. If you want to have more complex queries for the <EnableRule> then we can use <CustomRule> to call a JScript function. Please see my earlier post here: http://howto-mscrm.com/2011/04/how-to-series-6-how-to-use-customrule.html on how to use <CustomRule> with “HomePageGrid”.
Hope it helps everyone. 🙂

Cheers…!!!
Vikranth Pandiri.

11 thoughts on “How To – Series 7: How To override(Enable, Disable, Show, Hide, Custom Logic) Out of the Box HomePageGrid ribbon elements – CRM 2011

  1. Michael Dodd

    Vikranth,
    Great post. I was wondering if you could give me some additional advice on how to simply change the label of an OOTB ribbon button. In my case, I would like to change the label for a custom entity's "Deactivate" button to "Complete". The functionality would remain the same, in that I would not be replacing the button or adding functionality, simply changing the Label.
    Additionally, I don't know where to locate the OOTB ribbon.xml for custom entities. I can grab the OOTB entity Ribbon.xml from the SDK, but I don't know how to extract the custom entities.
    Any advice would be greatly appreciated.

  2. dyncrmblog Post author

    Thanks Dodd.
    Even to change only the Lable, I suggest you to go with the above approach as of now. I am still trying to findout simplest way to do it.
    All entities(even Custom) have OOTB ribbon elements defined based on the "applicationribbon.xml". In your case, note down the "Deactivate" button "Id" from the "applicationribbon.xml" and customize the "Custom" entity's "RibbonDiffXml" by adding "CustomAction" for the "Deactivate" button.
    Hope it helps you….
    I will come back with simplest solution to override ribbon elements if possible.

  3. MK

    Hi
    I tried these steps where I have to disable Add Existing Statdard button on Sub-Grid. But its now working nor is it throwing any error.

  4. MK

    Hi
    I tried these steps where I have to disable Add Existing Statdard button on Sub-Grid. But its now working nor is it throwing any error.

  5. Thorsten Klenke

    Hi Vikranth,
    I tried to enable the AddNewStandard Button of a subgrid if the value of a field (statuscode) on the coresponding entity has a special value (draft)

    I tried the following EnableRule

    It is possible with the value rule to get a value from a field of a relatet entity?

  6. Martin

    Hi Vikranth.
    As Michael, I am to rename the text of a button on the Fax entity.
    Do i really have to copy every little detail about this button from the ApplicationRibbon, and add to the RibbonDiffXml of the fax-xml….just to change the label?

    Please tell me it isn't so 🙂

  7. dyncrmblog Post author

    @ Thorsten Klenke: ValueRule only works with current entity field values. If you want to get a value from related entity then I suggest you to go with CustomRule instead.
    @Martin: There is no support from Microsoft to interact with the ribbon elements from Java Script code. So, for the time being I can suggest only the above approach.

  8. Rick Gipson

    Hello Vikranth,

    I've been working on some fairly extensive ribbon customizations and want to ask you for ideas on how to modify the the "New Record" flyout anchor menu.

    For example the Outlook 2003/2007 Toolbar "New Record" menu, it is set to PopulateDynamically and uses the "Mscrm.DynamicMenu.Outlook.NewRecord" as its PopulateQueryCommand. When I look at that CommandDefinition there are not , , defined. How would I go about customizing the this menu?

    Thanks,

    Rick

  9. Puneet

    hi Vikrant,

    Thanks for the blogs on CRM'11 as they are perfectly helpful in learning and in getting a clear picture with the entities and attributes. I have been trying to do an inline editing on grid and i found that it's a tedious task for the one specially who has started currently working on CRM'11, so can you please guide me through any fresh articles or books whatever where i can get a basic idea of this task?? thanks

Comments are closed.