Ribbon Customization-Part 4-Add a Custom Tab, Custom Group and Custom Buttons to a Grid Ribbon for a Specific Entity(Opportunity Entity)

In my earlier post we have seen how to add a custom tab to a specific entity

Today I am going to perform the following tasks

  1. Adding  a Custom Group to the  CRM 2011 Ribbon for a specific entity( I am taking opportunity entity for this purpose)
  2. Adding  a Custom Buttons to the Custom Group With the Specific Actions for the Buttons
    1. On Click of First Button we will open the “www.microsoft.com”
    2. On Click of the Second Button we will  call a simple Java script function Which exists in a web resource.

Coming to the Actions in sequence,

  • Create a new Solution called “OpportunitySolution” and add Opportunity entity  and a newly created web resource called ”ShowMessage.js” with the following Code
   1: function show(Val)

   2: {

   3: alert("Button "+Val+" action performed.");

   4: }

  • Publish the customizations
  • Export the Solutions and Save
  • Unzip the Solution and Edit the customizations.xml  with  any XML Editor  I prefer VS 2010.
  • search for <Entity> as shown the below screenshot Collapse the <FormXML> tag then you can see the <RibbonDiffXML> for the opportunity
  • Adding a Button to CRM 2011 Grid ribbon with specific actions to Opportunity Entity
  • Add the CustomActions to the RibbonDiffXMLwith the below code
  •    1: <CustomActions>

       2:        <CustomAction Id="Sample.Grid.opportunity.CustomTab.CustomAction" Location="Mscrm.Tabs._children" Sequence="40">

       3:          <CommandUIDefinition>

       4:            <Tab Id="Sample.Grid.opportunity.CustomTab" Command="Sample.Grid.opportunity.CustomTab" Title="$LocLabels:Sample.opportunity.CustomTab.Title" Description="$LocLabels:Sample.opportunity.CustomTab.Description" Sequence="500">

       5:              <Scaling Id="Sample.Grid.opportunity.CustomTab.Scaling">

       6:                <MaxSize Id="Sample.Grid.opportunity.CustomTab.FirstGroup.MaxSize" GroupId="Sample.Grid.opportunity.CustomTab.FirstGroup" Sequence="10" Size="LargeMedium" />

       7:              </Scaling>

       8:              <Groups Id="Sample.Grid.opportunity.CustomTab.Groups">

       9:                <Group Id="Sample.Grid.opportunity.CustomTab.FirstGroup" Command="Sample.Grid.opportunity.FirstGroup" Sequence="10" Title="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.Title" Template="Mscrm.Templates.3.3">

      10:                  <Controls Id="Sample.Grid.opportunity.CustomTab.FirstGroup.Controls">

      11:                    <Button Id="Sample.Grid.opportunity.CustomTab.FirstGroup.FirstButton" ToolTipTitle="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.FirstButton.LabelText"

      12:                            ToolTipDescription="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.FirstButton.ToolTipDescription"

      13:                            Command="Sample.Grid.opportunity.FirstButton"

      14:                            Sequence="10"

      15:                            LabelText="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.FirstButton.LabelText"

      16:                            Alt="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.FirstButton.LabelText"

      17:                            Image16by16="/_imgs/ribbon/AddEmail_16.png"

      18:                            Image32by32="/_imgs/ribbon/Email_32.png" TemplateAlias="o1" />

      19:                    <Button Id="Sample.Grid.opportunity.CustomTab.FirstGroup.SecondButton"

      20:                            ToolTipTitle="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.SecondButton.LabelText"

      21:                            ToolTipDescription="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.SecondButton.ToolTipDescription"

      22:                            Command="Sample.Grid.opportunity.SecondButton"

      23:                            Sequence="20"

      24:                            LabelText="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.SecondButton.LabelText"

      25:                            Alt="$LocLabels:Sample.opportunity.CustomTab.FirstGroup.SecondButton.LabelText"

      26:                            Image16by16="/_imgs/ribbon/AddEmail_16.png"

      27:                            Image32by32="/_imgs/ribbon/Email_32.png" TemplateAlias="o1" />

      28:  

      29:                  </Controls>

      30:                </Group>

      31:              </Groups>

      32:            </Tab>

      33:          </CommandUIDefinition>

      34:        </CustomAction>

      35:      </CustomActions>

  • Add the Templates with the following code
  •    1: <Templates>

       2:          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>

       3:        </Templates>

  • Add the <<CommandDefinitions>> with the below code
  •    1: <CommandDefinitions>

       2:          <CommandDefinition Id="Sample.Grid.opportunity.CustomTab">

       3:            <EnableRules>

       4:              <EnableRule Id="Mscrm.Enabled " />

       5:            </EnableRules>

       6:            <DisplayRules>

       7:              <DisplayRule Id="Mscrm.CanWriteOpportunity" />

       8:            </DisplayRules>

       9:            <Actions />

      10:          </CommandDefinition>

      11:          <CommandDefinition Id="Sample.Grid.opportunity.FirstGroup">

      12:            <EnableRules>

      13:              <EnableRule Id="Mscrm.Enabled " />

      14:            </EnableRules>

      15:            <DisplayRules>

      16:              <DisplayRule Id="Mscrm.CanWriteOpportunity" />

      17:            </DisplayRules>

      18:            <Actions />

      19:          </CommandDefinition>

      20:          <CommandDefinition Id="Sample.Grid.opportunity.FirstButton">

      21:            <EnableRules/>

      22:            <DisplayRules/>

      23:            <Actions>

      24:              <Url Address ="http://www.microsoft.com"></Url>

      25:            </Actions>

      26:          </CommandDefinition>

      27:          <CommandDefinition Id="Sample.Grid.opportunity.SecondButton">

      28:            <EnableRules/>

      29:            <DisplayRules/>

      30:            <Actions>

      31:              <JavaScriptFunction Library="$webresource:new_/ShowMessage.js" FunctionName="show">

      32:                <StringParameter Value="2" />

      33:              </JavaScriptFunction>

      34:            </Actions>

      35:          </CommandDefinition >

  • Observe how I have added the Actions for the buttons ,generally actions are performed by ribbon controls and these are of 2 types
    • Java script functions
    • Opening an UL
  • If you observe the First button action is “Opening an URL”
  • For  the Second Button action is –On click of the Button it would show the Message from the Java Script Function and also passing a string parameter from the Ribbon control to the JavaScript function
  • Add the <<RuleDefinitions>> with the Following code
  •    1: <RuleDefinitions>

       2:         <TabDisplayRules>

       3:           <TabDisplayRule TabCommand="Sample.Grid.opportunity.CustomTab">

       4:             <EntityRule EntityName="opportunity" Context="HomePageGrid" />

       5:           </TabDisplayRule>

       6:         </TabDisplayRules>

       7:         <DisplayRules/>

       8:         <EnableRules />

       9:       </RuleDefinitions>

  • In the Rule Definition I specified  exclusively that the buttons should appear on the Grid Ribbon only. Not on the Form Ribbon and Sub Grid Ribbon
  • Add the <LocLables> with the below code
  •    1: <LocLabels>

       2:        <LocLabel Id="Sample.opportunity.CustomTab.FirstGroup.FirstButton.LabelText">

       3:          <Titles>

       4:            <Title languagecode="1033" description="First Button" />

       5:          </Titles>

       6:        </LocLabel>

       7:        <LocLabel Id="Sample.opportunity.CustomTab.Description">

       8:          <Titles>

       9:            <Title languagecode="1033" description="A custom tab for the Opportunity entity." />

      10:          </Titles>

      11:        </LocLabel>

      12:        <LocLabel Id="Sample.opportunity.CustomTab.FirstGroup.Title">

      13:          <Titles>

      14:            <Title languagecode="1033" description="First Group" />

      15:          </Titles>

      16:        </LocLabel>

      17:        <LocLabel Id="Sample.opportunity.CustomTab.FirstGroup.FirstButton.ToolTipDescription">

      18:          <Titles>

      19:            <Title languagecode="1033" description="The first button in the first group." />

      20:          </Titles>

      21:        </LocLabel>

      22:        <LocLabel Id="Sample.opportunity.CustomTab.Title">

      23:          <Titles>

      24:            <Title languagecode="1033" description="Custom Tab" />

      25:          </Titles>

      26:        </LocLabel>

      27:        <LocLabel Id="Sample.opportunity.CustomTab.FirstGroup.SecondButton.LabelText">

      28:          <Titles>

      29:            <Title languagecode="1033" description="Second Button" />

      30:          </Titles>

      31:        </LocLabel>

      32:        <LocLabel Id="Sample.opportunity.CustomTab.FirstGroup.SecondButton.ToolTipDescription">

      33:          <Titles>

      34:            <Title languagecode="1033" description="The second button in the first group." />

      35:          </Titles>

      36:        </LocLabel>

      37:      </LocLabels>

  • Check the below screenshots  for the functionality
  • Initial display of the buttons on the Opportunity Entity Grid ribbon
  • Adding Buttons on the Grid Ribbon
  • On Click of the  first button an window will open with the URL www.microsoft.com as shown the below screenshot
  • Opening a URL from the CRM2011 Ribbon Button
  • On Click of the second Button  the result look like below screenshot and the “2” is the string parameter we passed to the JavaScript function
  • CRM2011 Ribbon Button Action
  • You can download the Complete Solution from here

Happy Learning Smile

Advertisements

2 Responses to Ribbon Customization-Part 4-Add a Custom Tab, Custom Group and Custom Buttons to a Grid Ribbon for a Specific Entity(Opportunity Entity)

  1. Pingback: Dynamics CRM 2011 Ribbon Customization Index « Siva's Dynamics CRM 2011 Blog

  2. Pingback: Dynamics CRM 2011 Ribbon Customization Index « Siva's Dynamics CRM 2011 Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: