Thursday 23 February 2012

CRM 2011 – Create Ribbon Popup buttons on entity ribbon

Dynamics CRM 2011 allows us to export a solution as managed or unmanaged solution. This solution is having the customization.xml file which contains all or selected portions of the customizations and configurations for your system. In this post I have described what to change in customization.xml file to have Ribbon popup button as shown in below screen shot.

clip_image001[4]

1. Create a Solution or use an existing one.
2. Select components.

clip_image003[4]

3. Add entity for which you want to edit the ribbon, in this example I have added “Flight Route” entity (a custom entity).
4. Export the solution with unmanaged option.
5. Unzip all files and open customizations.xml in visual studio.
6. Once you open it you could find RibbonDiffxml tag underneath an Entity node. In below screen shot I have highlighted the RibbonDiffXml of “Flight Route” entity.











Once you expand this element, you could see below xml

<RibbonDiffXml>
    <CustomActions />
   <Templates>
    <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>   
   </Templates>
   <CommandDefinitions />
   <RuleDefinitions>
  <TabDisplayRules />
  <DisplayRules />
  <EnableRules />
  </RuleDefinitions>
  <LocLabels />
</RibbonDiffXml>
In above screen shot I have highlighted 3 important elements of RibbonDiffXml xml. You need to replace those empty nodes with below xml.

Replace CustomActions with below xml content. In this example I have specified a publisher of solution with prefix as “acm”. My custom entity is acm_filightroute and a group name is “Airport”.

You need to replace these values with yours via find and replace feature of visual studio. Also change the label text and tool tip values  as per your need.
<CustomActions>
<CustomAction Id="acm.Form.acm_flightroute.MainTab.Airport.CustomAction" Location="Mscrm.Form.acm_flightroute.MainTab.Groups._children" Sequence="10">
<CommandUIDefinition>
<Group Id="acm.Form.acm_flightroute.MainTab.Airport" 
Command="Mscrm.Enabled" 
Template="Mscrm.Templates.Flexible2" 
Sequence="100" 
Title="$LocLabels:acm.Form.acm_flightroute.MainTab.Airport.TitleText" 
Description="$LocLabels:acm.Form. acm_flightroute.MainTab.Airport.DescriptionText">
<Controls Id="acm.Form.acm_flightroute.MainTab.Airport.Controls">
<SplitButton Id="acm.Form.acm_flightroute.MainTab.AirportPopUp" 
ToolTipTitle="Airport Popup Menu" 
ToolTipDescription="Popup Menu for Airport Entity" 
Command="Mscrm.Enabled" 
Sequence="20" 
LabelText="Airport PopUp Menu" 
Alt="Airport PopUp Menu" 
TemplateAlias="o1">
<Menu Id="acm.Form.acm_flightroute.MainTab.AirportPopUp.Menu">
<MenuSection Id="acm.Form.acm_flightroute.MainTab.AirportPopUp.MenuSection" 
Sequence="10" 
DisplayMode="Menu16">
<Controls Id="acm.Form.acm_flightroute.MainTab.AirportPopUp.Controls">
<Button Id="acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport" 
Command="acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.Command" 
Sequence="20" 
ToolTipTitle="$LocLabels:acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.LabelText" 
LabelText="$LocLabels:acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.LabelText" 
ToolTipDescription="$LocLabels:acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.Description" 
TemplateAlias="o1" Image16by16="$webresource:acm_/Images/sample_iconsTIcon16x16png" Image32by32="$webresource:acm_/Images/sample_iconsTIcon32x32png" />
<Button Id="acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog" Command="acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.Command" Sequence="20" ToolTipTitle="$LocLabels:acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.LabelText" LabelText="$LocLabels:acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.LabelText" ToolTipDescription="$LocLabels:acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.Description" TemplateAlias="o1" Image16by16="$webresource:acm_/Images/sample_iconsTIcon16x16png" Image32by32="$webresource:acm_/Images/sample_iconsTIcon32x32png" />
</Controls>
</MenuSection>
</Menu>
</SplitButton>
</Controls>
</Group>
</CommandUIDefinition>
</CustomAction>
<CustomAction Id="acm.Form.acm_flightroute.MainTab.Airport.MaxSize.CustomAction" Location="Mscrm.Form.acm_flightroute.MainTab.Scaling._children" Sequence="10">
<CommandDefinitions>
<CommandUIDefinition>
<MaxSize Id="acm.Form.acm_flightroute.MainTab.Airport.MaxSize" GroupId="acm.Form.acm_flightroute.MainTab.Airport" Sequence="10" Size="LargeMedium" />
</CommandUIDefinition>
</CustomAction>
<CustomAction Id="acm.Form.acm_flightroute.MainTab.Airport.Scale.Popup.CustomAction" Location="Mscrm.Form.acm_flightroute.MainTab.Scaling._children" Sequence="10">
<CommandUIDefinition>
<Scale Id="acm.Form.acm_flightroute.MainTab.Airport.Scale.Popup" GroupId="acm.Form.acm_flightroute.MainTab.Airport" Sequence="300" Size="Popup" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>

Below is a command definition tag. Replace the prefix and other values here as well.

<CommandDefinition Id="acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.Command">
<EnableRules />
<DisplayRules />
<Actions>
<JavaScriptFunction FunctionName="CreateAirport" Library="$webresource:acm_/javascripts/LaunchNewEntry.js" />
</Actions>
</CommandDefinition>
<CommandDefinition Id="acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.Command">
<EnableRules />
<DisplayRules />
<Actions>
<JavaScriptFunction FunctionName="LaunchModalDialog" Library="$webresource:acm_/javascripts/LaunchModalDialog.js">
<StringParameter Value="{e1e36d96-ced2-4ede-85e8-455e3cf4daaf}" />
<StringParameter Value="acm_flightroute" />
<CrmParameter Value="FirstPrimaryItemId" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
 
 

Apply the same procedure to below xml too.

<LocLabels>
<LocLabel Id="acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.Description">
<Titles>
<Title languagecode="1033" description="Insert New Airport Description" />
</Titles>
</LocLabel>
<LocLabel Id="acmacm.Form.acm_flightroute.MainTab.Airport.InsertNewAirport.LabelText">
<Titles>
<Title languagecode="1033" description="Insert New Airport" />
</Titles>
</LocLabel>
<LocLabel Id="acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.Description">
<Titles>
<Title languagecode="1033" description="Show Dialog Description" />
</Titles>
</LocLabel>
<LocLabel Id="acmacm.Form.acm_flightroute.MainTab.Airport.ShowDialog.LabelText">
<Titles>
<Title languagecode="1033" description="Show Dialog" />
</Titles>
</LocLabel>
</LocLabels>

7. Save Customization.xml.
8. Create a Zip file of all extracted files (in Step 5) including the updated customization.xml.

clip_image002

9. Import this newly created zip file back to CRM server.
10. Open entity form on which you have implemented popup button.
11. In my case I can see “Airport Popup Menu” in Airport group with Dropdown as shown below.

clip_image004

12. On click Dropdown button you can see two buttons.

clip_image006

10 comments:

  1. Hi,

    Really helpful post.

    Is it possible to have an image on the main button as well?

    Thanks

    ReplyDelete
  2. Yes, it is.
    Please refer below blog post for the same.
    http://ankit.inkeysolutions.com/2012/01/crm-2011-how-to-use-visual-ribbon.html

    ReplyDelete
  3. Hi,
    I referred your blog and added split button to custom entity form ribbon.But out of 10 buttons only two button is enabled for click and other is in disabled mode.

    Why like that ?


    ReplyDelete
  4. Hi,
    I refered your blog and added custom split button to custom form ribbon.Here out of 10 buttons only first two button are enabled and renaming are in disabled mode.

    What is the reason for this ?

    ReplyDelete
  5. Hi, I am trying this in Dynamics 2013, But i am getting an Error "The import file is invalid. XSD validation failed with the following error: '{0}'. The validation failed at: '...{1} <<<<>>>> {2}...'.""

    ReplyDelete
  6. Hi, I suggest you to evaluate Ribbon Workbench tool to do so. For more details please refer following link:
    http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx

    ReplyDelete
  7. Hi Ankit,
    In my current project I would like to make dropdown for Ribbon buttons.

    for an example under Records below buttons should come

    New, Edit, delete .


    I am using Split button to achieve this but this split button is not showing all the buttons that I created under split button.

    ReplyDelete
    Replies
    1. Hi, Please add a menu item first at ribbon workbench and add a command for this item.

      Then associate that newly created command to the ribbon button.

      With these steps it should display the button under the split button.

      Can you please confirm that you perform the second step?

      Delete
  8. Hi Ankit, I´m trying to add a splitButton into a spitButton but it doesn´t work. Is there a code to do something similar? Thanks!!

    ReplyDelete
  9. Hi,

    According to my understanding it's not possible to add split button into another split button. Instead we can add Flyout menu into the split button and then add a simple button to that flyout.

    ReplyDelete