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

Sunday, 27 February 2011

How to place a custom button on the main page (Application Ribbon) of MS Dynamics CRM 2011

This post explains how to place a custom button on the main page of  MS Dynamics CRM 2011.
Lets place a simple button Google and when we click it we should get a popup window with Google.com page.

Firstly lets create a new solution. Let's name it as Ribbon.


After the creation go to the solution and navigate to components. And then choose Add Existing option and click on Application Ribbons. The purpose of this action is to obtain the standard tags in our customization file.
Application Ribbon has been added to the Solution as shown below.



As you all know the next action is Publish the solution.

Lets export the customizations of this solution.




You could choose Unmanaged or Managed according to the requirement.
For the time being lets opt Unmanaged.


Save the customization file to the local folder

When we extract this zipped file, we could see the customizations.xml

Open the Customizations.xml preferably with a Visual Studio editor or with any good xml editor. Readability is a key factor while editing xml files.

As shown above we need to place some code for the custom actions and also command definitions.

Our target is to place a button on the main page next to Start Dialog button. In the above screen shot Accounts is a tab. This tab will change according to entity. Currently its showing Accounts because we chose Accounts. Our button will be displayed on the main page for all entities.

Here is the key word for this scenario
Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab 
Tab displays the plural entity display name in the label.

A few other tabs could be identified as 

Mscrm.HomepageGrid.{!EntityLogicalName}.View 
Tab has the label View.

Mscrm.HomepageGrid.{!EntityLogicalName}.Related 
Tab has the label Add.

Mscrm.HomepageGrid.{!EntityLogicalName}.Developer 
Tab has the label Customize.

Each Tab is divided into Groups and then Controls

Tab----> Group1,Group2,Group3....etc
Group-->Control1,Control2,etc


The above sample XML could be found in SDK. Its helpful if we refer this to identify clearly where we are going to place the button. Also we can see the attribute values.



Location="Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab.Workflow.Controls._children"
Location is a key attribute which determines the location of the new button.
Also Command="Sample.all.MainTab.MyURL.Command" determines the action to be taken by referring to the Command definitions as shown above.

Following is our new Customization file.

<ImportExportXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Entities></Entities>
  <Roles></Roles>
  <Workflows></Workflows>
  <FieldSecurityProfiles></FieldSecurityProfiles>
  <Templates />
  <RibbonDiffXml>
    <CustomActions>
      <CustomAction Id ="Sample.{!EntityLogicalName}.MainTab.MyURL.CustomAction" Sequence="41"
                    Location="Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab.Workflow.Controls._children">
        <CommandUIDefinition>
          <Button Id="Sample.{!EntityLogicalName}.MainTab.MyURL.Button"
                    Command="Sample.all.MainTab.MyURL.Command"
                    LabelText="Google" ToolTipTitle="Google"
                    ToolTipDescription="Google" TemplateAlias="o1" />

        </CommandUIDefinition>
      </CustomAction>
    </CustomActions>
    <Templates>
      <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
    </Templates>
    <CommandDefinitions>
      <CommandDefinition Id="Sample.all.MainTab.MyURL.Command">
        <EnableRules />
        <DisplayRules />
        <Actions>
          <Url Address="http://www.google.com" />
        </Actions>
      </CommandDefinition>
    </CommandDefinitions >
    <RuleDefinitions>
      <TabDisplayRules />
      <DisplayRules />
      <EnableRules />
    </RuleDefinitions>
    <LocLabels />
  </RibbonDiffXml>
  <EntityMaps />
  <EntityRelationships />
  <OrganizationSettings>
    <customization>
      <isappmode>False</isappmode>
    </customization>
  </OrganizationSettings>
  <optionsets />
  <Languages>
    <Language>1033</Language>
  </Languages>
</ImportExportXml>



After this we could compress and export the customizations back to the MS Dynamics CRM 2011.







After the publish process, refresh the CRM URL and navigate to Workplace and click Accounts on the left navigation. You could see a button called "Google" on the application ribbon. If you click on it, you could see a popup with Google.com in it.

If you choose Contacts then you could see the same button on the same place.











1 comment: