Adding a Ribbon Button to SubGrid in CRM 2011

Posted: November 9, 2012 in CRM 2011, Ribbons

Adding a Custom Tab and Group to SubGrid in CRM 2011

Here i need to add a custom button by creating a new custom tab to the subgrid.

In my case I’m going to add sub grid button for opportunity entity. Create a new solution, add the opportunity entity and export the solution.

Open the customizations.xml file and replace the <RibbonDiffXml> with following code

<RibbonDiffXml>
        <CustomActions>
          <CustomAction Id="Mscrm.SubGrid.opportunity.CustomTab.CustomAction" Location="Mscrm.SubGrid.opportunity.ContextualTabs._children" Sequence="40">
            <CommandUIDefinition>
              <Tab Id="Mscrm.SubGrid.opportunity.CustomTab" Command="Mscrm.SubGrid.opportunity.CustomTab" Title="$LocLabels:Mscrm.SubGrid.opportunity.CustomTab.Title" Description="$LocLabels:Mscrm.SubGrid.opportunity.CustomTab.Title" Sequence="500">
                <Scaling Id="Mscrm.SubGrid.opportunity.CustomTab.Scaling">
                  <MaxSize Id="Mscrm.SubGrid.opportunity.CustomTab.CustomGroup.MaxSize" GroupId="Mscrm.SubGrid.opportunity.CustomTab.CustomGroup" Sequence="10" Size="LargeMedium" />
                </Scaling>
                <Groups Id="Mscrm.SubGrid.opportunity.CustomTab.Groups">
                  <Group Id="Mscrm.SubGrid.opportunity.CustomTab.CustomGroup" Command="Mscrm.SubGrid.opportunity.CustomGroup" Sequence="10" Title="$LocLabels:Mscrm.SubGrid.opportunity.CustomGroup.Title" Template="Mscrm.Templates.3.3">
                    <Controls Id="Mscrm.SubGrid.opportunity.CustomTab.CustomGroup.Controls">
                      <Button Id="Mscrm.SubGrid.opportunity.CustomTab.CustomGroup.CustomButton" ToolTipTitle="$LocLabels:Mscrm.SubGrid.opportunity.CustomButton.ToolTip" ToolTipDescription="$LocLabels:Mscrm.SubGrid.opportunity.CustomButton.ToolTip" Command="Mscrm.SubGrid.opportunity.CustomButton" Sequence="10" LabelText="$LocLabels:Mscrm.SubGrid.opportunity.CustomButton.LabelText" Image16by16="/_imgs/Ribbon/Enable_16.png" Image32by32="/_imgs/Ribbon/Enable_32.png" TemplateAlias="o1" />
                    </Controls>
                  </Group>
                </Groups>
              </Tab>
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <CommandDefinition Id="Mscrm.SubGrid.opportunity.CustomButton">
            <EnableRules>
              <EnableRule Id="Mscrm.Enabled" />
            </EnableRules>
            <DisplayRules/>
            <Actions>
              <JavaScriptFunction Library="$webresource:crm_accountjscript" FunctionName="RibbonButtonClick" />
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.SubGrid.opportunity.CustomTab">
            <EnableRules>
              <EnableRule Id="Mscrm.Enabled" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Mscrm.SubGrid.opportunity.CustomTab.DisplayRule" />
            </DisplayRules>
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.SubGrid.opportunity.CustomGroup">
            <EnableRules>
              <EnableRule Id="Mscrm.Enabled" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Mscrm.SubGrid.opportunity.CustomGroup.DisplayRule" />
            </DisplayRules>
            <Actions />
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules>
            <TabDisplayRule TabCommand="Mscrm.SubGrid.opportunity.CustomTab">
              <EntityRule EntityName="opportunity" Context="SubGridStandard" />
              <EntityRule EntityName="opportunity" Context="SubGridAssociated" />
            </TabDisplayRule>
          </TabDisplayRules>
          <DisplayRules>
            <DisplayRule Id="Mscrm.SubGrid.opportunity.CustomTab.DisplayRule">
              <CrmClientTypeRule Type="Web" />
            </DisplayRule>
            <DisplayRule Id="Mscrm.SubGrid.opportunity.CustomGroup.DisplayRule">
              <CrmClientTypeRule Type="Web" />
            </DisplayRule>
          </DisplayRules>
          <EnableRules>
            <EnableRule Id="Mscrm.Enabled">
              <CrmClientTypeRule Type="Web" />
            </EnableRule>
          </EnableRules>
        </RuleDefinitions>
        <LocLabels>
          <LocLabel Id="Mscrm.SubGrid.opportunity.CustomButton.LabelText">
            <Titles>
              <Title languagecode="1033" description="Custom Button" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Mscrm.SubGrid.opportunity.CustomButton.ToolTip">
            <Titles>
              <Title languagecode="1033" description="Custom Button" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Mscrm.SubGrid.opportunity.CustomGroup.Title">
            <Titles>
              <Title languagecode="1033" description="Custom Group" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Mscrm.SubGrid.opportunity.CustomTab.Title">
            <Titles>
              <Title languagecode="1033" description="Custom Tab" />
            </Titles>
          </LocLabel>
        </LocLabels>
      </RibbonDiffXml>

After replacing the code save the file and import the solution into the CRM.

Make sure the jscript file and function name exists in your webresource. Below is my jscript function

function RibbonButtonClick() {
    alert("Ribbon click fired");
}

Adding a Ribbon Button in Custom Group to SubGrid in CRM 2011

<RibbonDiffXml>
        <CustomActions>
          <CustomAction Id="Mscrm.Isv.opportunity.subgrid.MaxSizeCustomAction" Location="Mscrm.SubGrid.opportunity.MainTab.Scaling._children" Sequence="110">
            <CommandUIDefinition>
              <MaxSize Id="Mscrm.Isv.opportunity.subgrid.MaxSize" GroupId="Mscrm.Isv.opportunity.subgrid.Group0" Sequence="21" Size="LargeLarge" />
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.Isv.opportunity.subgrid.ScaleSizeCustomAction" Location="Mscrm.SubGrid.opportunity.MainTab.Scaling._children" Sequence="130">
            <CommandUIDefinition>
              <Scale Id="Mscrm.Isv.opportunity.subgrid.Popup.1" GroupId="Mscrm.Isv.opportunity.subgrid.Group0" Sequence="85" Size="Popup" />
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.Isv.opportunity.subgrid.SubgridCustomAction" Location="Mscrm.SubGrid.opportunity.MainTab.Groups._children" Sequence="300">
            <CommandUIDefinition>
              <Group Id="Mscrm.Isv.opportunity.subgrid.Group0" Sequence="600" Command="Mscrm.Isv.opportunity.subgrid.Group0" Title="$LocLabels:Mscrm.Isv.opportunity.CustomGroup.LabelText" Template="Mscrm.Templates.Flexible2">
                <Controls Id="Mscrm.Isv.opportunity.subgrid.Controls">
                  <Button Id="Mscrm.Isv.opportunity.form.CustomButton.Button"
                              Command="Mscrm.Isv.opportunity.form.CustomButton.Command"
                              LabelText="$LocLabels:Mscrm.Isv.opportunity.CustomButton.LabelText"
                              ToolTipTitle="$LocLabels:Mscrm.Isv.opportunity.CustomButton.LabelText"
                              ToolTipDescription="$LocLabels:Mscrm.Isv.opportunity.CustomButton.ToolTip"
                              TemplateAlias="o1"
                              Image16by16="/_imgs/Ribbon/Enable_16.png"
                              Image32by32="/_imgs/Ribbon/Enable_32.png" />
                </Controls>
              </Group>
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <CommandDefinition Id="Mscrm.Isv.opportunity.subgrid.Command">
            <EnableRules />
            <DisplayRules>
              <DisplayRule Id="Mscrm.Isv.opportunity.subgrid.Notify.DisplayRule" />
            </DisplayRules>
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.Isv.opportunity.subgrid.Group0">
            <EnableRules />
            <DisplayRules>
              <DisplayRule Id="Mscrm.Isv.opportunity.subgrid.Notify.DisplayRule" />
            </DisplayRules>
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.Isv.opportunity.form.CustomButton.Command">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <JavaScriptFunction Library="$webresource:crm_accountjscript" FunctionName="RibbonButtonClick" />
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules>
            <DisplayRule Id="Mscrm.Isv.opportunity.subgrid.Notify.DisplayRule">
              <CrmClientTypeRule Type="Web" />
            </DisplayRule>
          </DisplayRules>
          <EnableRules />
        </RuleDefinitions>
        <LocLabels>
          <LocLabel Id="Mscrm.Isv.opportunity.CustomButton.ToolTip">
            <Titles>
              <Title languagecode="1033" description="Custom Button" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Mscrm.Isv.opportunity.CustomButton.LabelText">
            <Titles>
              <Title languagecode="1033" description="Custom Button" />
            </Titles>
          </LocLabel>
          <LocLabel Id="Mscrm.Isv.opportunity.CustomGroup.LabelText">
            <Titles>
              <Title languagecode="1033" description="Custom Group" />
            </Titles>
          </LocLabel>
        </LocLabels>
      </RibbonDiffXml>

Advertisements

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