"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Saturday 5 November 2011

Customize Ribbon Tab, Group, Button in CRM 2011 OR How to insert a custom tab at Ribbon area in CRM 2011

Let's see how to customize a ribbon tab in CRM 2011 with a group and a few buttons in it. Remember there are some pitfalls while customizing ribbon tab in CRM 2011. So we are going to crack the nut.


In the following screen shot, please note the following.


1. Tab - Departments
2. Group 1- Marketing
3. Group 2.- Sales
4. Button Legal under Marketing Group
5. Button Public Relations under Marketing under Marketing Group
6. Button Customer under Sales under Sales Group





So obviously the hierarchy is 

Tab--Group--Button

So our nut is " Place a new tab for Account entity form with groups Marketing (2 buttons) and Sales (1 button)"

Lets have a look at the customization.xml. Our playground is the area under RibbonDiffXml.

To make it more simple, lets have a broad view at 4 main regions.

1. Custom Actions -- Where you could define tab, group ,button etc
2. Command definitions -Where you could define the action on the button or group
3. Rule Definitions-- Show / Hide or Enable Disable rule definitions
4. LocLabels --For Localization of labels.

So first we would have a look at the 1.Custom Actions 

Pitfall : Scaling
Scaling is one of the pitfalls.  Scaling defines how the groups are presented to the Ribbon. There is a tag called Maxsize which defines largest layout possible for a group. Now the pitfall is, if you have 2 groups you must define 2 Maxsize as shown. Otherwise it would display tab, group but no buttons on it.

Secondly, 2. Command Definitions


Please note the bridge between the Custom Action and Command Definition is Command ID.
While defining a tab, group or button we are defining a Command.

Pitfall: If you define a command for tab, group or button, you should use the same as Command ID in Command definition to define an action.

Here we are calling javascript function in Actions. You could also define DisplayRules and EnableRules if you want to.

Now we are into 3rd level , 3. Rule Definitions.


This shows how we could define the display rule for a tab. In our case we would like to display the tab ONLY on the entity form. So the context is Form

Following are possible scope of Context:

Form --For the form ribbon.

HomePageGrid---For the ribbon that is displayed for the list of records that appear in the main application navigation pane.

SubGridStandard --For the ribbon that is displayed for the list of records that appear in a subgrid in a form.

SubGridAssociated ---For the ribbon that is displayed for the list of records that appear in the navigation area of a form.



and thus we reached 4th level which is 4. LocLabels.

This is very simple and its used for Localization of labels. Remember the fact that ID is the link to refer these labels.


For your convenience, the whole code is given below.

<RibbonDiffXml>
        <CustomActions>
          <CustomAction Id="Mscrm.Isv.GlobalCustomAction" Location="Mscrm.Tabs._children" Sequence="100">
            <CommandUIDefinition>
              <Tab Id="account.DepartmentsTab" Command="Mscrm.account.DepartmentsTab" Description="$LocLabels:Account.Form.Departments.LabelText" Title="$LocLabels:Account.Form.Departments.LabelText" Sequence="1000">
                <Scaling Id="account.DepartmentsTab.Scaling">
                  <MaxSize Id="account.DepartmentsTab.Group0.MaxSize" Sequence="10" GroupId="account.DepartmentsTab.Group0" Size="Large" />
                  <MaxSize Id="account.DepartmentsTab.Group1.MaxSize" Sequence="20" GroupId="account.DepartmentsTab.Group1" Size="Large" />
                </Scaling>
                <Groups Id="account.DepartmentsTab.Groups">
                  <Group Id="account.DepartmentsTab.Group0" Sequence="10" Command="account.DepartmentsTab.Group0" Description="$LocLabels:Account.Form.Marketing.LabelText" Title="$LocLabels:Account.Form.Marketing.LabelText" Template="Mscrm.Templates.Flexible">
                    <Controls Id="account.DepartmentsTab.Group0.Controls"></Controls>
                  </Group>
                  <Group Id="account.DepartmentsTab.Group1" Sequence="11" Command="account.DepartmentsTab.Group1" Description="$LocLabels:Account.Form.Sales.LabelText" Title="$LocLabels:Account.Form.Sales.LabelText" Template="Mscrm.Templates.Flexible">
                    <Controls Id="account.DepartmentsTab.Group1.Controls"></Controls>
                  </Group>
                </Groups>
              </Tab>
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.Form.account.Legal" Sequence="55" Location="account.DepartmentsTab.Group0.Controls._children">
            <CommandUIDefinition>
              <Button Id="Mscrm.Form.account.LegalButton" TemplateAlias="o1" Image16by16="$webresource:ap_btn.png" Image32by32="$webresource:ap_btn.png" LabelText="$LocLabels:Account.Form.Legal.LabelText" ToolTipTitle="$LocLabels:Account.Form.Legal.Tooltip" ToolTipDescription="$LocLabels:Account.Form.Legal.TooltipDescription" Command="Mscrm.Form.account.Legal.Command" />
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.Form.account.PublicRelations" Sequence="55" Location="account.DepartmentsTab.Group0.Controls._children">
            <CommandUIDefinition>
              <Button Id="Mscrm.Form.account.PublicRelationsButton" Image16by16="$webresource:ap_btn.png" Image32by32="$webresource:ap_btn.png" TemplateAlias="o1" LabelText="$LocLabels:Account.Form.PublicRelations.LabelText" ToolTipTitle="$LocLabels:Account.Form.PublicRelations.Tooltip" ToolTipDescription="$LocLabels:Account.Form.PublicRelations.TooltipDescription" Command="Mscrm.Form.account.PublicRelations.Command" />
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.Form.account.Customer" Sequence="55" Location="account.DepartmentsTab.Group1.Controls._children">
            <CommandUIDefinition>
              <Button Id="Mscrm.Form.account.CustomerButton" Image16by16="$webresource:ap_btn.png" Image32by32="$webresource:ap_btn.png" TemplateAlias="o1" LabelText="$LocLabels:Account.Form.Customer.LabelText" ToolTipTitle="$LocLabels:Account.Form.Customer.Tooltip" ToolTipDescription="$LocLabels:Account.Form.Customer.TooltipDescription" Command="Mscrm.Form.account.Customer.Command" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <CommandDefinition Id="account.DepartmentsTab.Group0">
            <EnableRules />
            <DisplayRules />
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="account.DepartmentsTab.Group1">
            <EnableRules />
            <DisplayRules />
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.Form.account.Legal.Command">
            <EnableRules></EnableRules>
            <DisplayRules>
            </DisplayRules>
            <Actions>
              <JavaScriptFunction Library="$webresource:ap_legal.js" FunctionName="Legal" />
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.Form.account.PublicRelations.Command">
            <EnableRules></EnableRules>
            <DisplayRules>
            </DisplayRules>
            <Actions>
              <JavaScriptFunction Library="$webresource:ap_publicrelations.js" FunctionName="PublicRelations" />
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.Form.account.Customer.Command">
            <EnableRules></EnableRules>
            <DisplayRules>
            </DisplayRules>
            <Actions>
              <JavaScriptFunction Library="$webresource:ap_customer.js" FunctionName="Customer" />
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules>
            <TabDisplayRule TabCommand="Mscrm.account.DepartmentsTab">
              <EntityRule EntityName="account" Context="Form" />
            </TabDisplayRule>
          </TabDisplayRules>
          <DisplayRules />
          <EnableRules />
        </RuleDefinitions>
        <LocLabels>
          <LocLabel Id="Account.Form.Departments.LabelText">
            <Titles>
              <Title languagecode="1033" description="Departments" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Departments.Tooltip">
            <Titles>
              <Title languagecode="1033" description="Departments" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Departments.TooltipDescription">
            <Titles>
              <Title languagecode="1033" description="Departments" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Marketing.LabelText">
            <Titles>
              <Title languagecode="1033" description="Marketing" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Marketing.Tooltip">
            <Titles>
              <Title languagecode="1033" description="Marketing" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Marketing.TooltipDescription">
            <Titles>
              <Title languagecode="1033" description="Marketing" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Sales.LabelText">
            <Titles>
              <Title languagecode="1033" description="Sales" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Sales.Tooltip">
            <Titles>
              <Title languagecode="1033" description="Sales" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Sales.TooltipDescription">
            <Titles>
              <Title languagecode="1033" description="Sales" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Legal.LabelText">
            <Titles>
              <Title languagecode="1033" description="Legal" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Legal.Tooltip">
            <Titles>
              <Title languagecode="1033" description="Legal" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Legal.TooltipDescription">
            <Titles>
              <Title languagecode="1033" description="Legal" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.PublicRelations.LabelText">
            <Titles>
              <Title languagecode="1033" description="Public Relations" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.PublicRelations.Tooltip">
            <Titles>
              <Title languagecode="1033" description="Public Relations" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.PublicRelations.TooltipDescription">
            <Titles>
              <Title languagecode="1033" description="Public Relations" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Customer.LabelText">
            <Titles>
              <Title languagecode="1033" description="Customer" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Customer.Tooltip">
            <Titles>
              <Title languagecode="1033" description="Customer" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Account.Form.Customer.TooltipDescription">
            <Titles>
              <Title languagecode="1033" description="Customer" />
            </Titles>
          </LocLabel>
        </LocLabels>
      </RibbonDiffXml>



So here is our cracked nut.







1 comment: