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

Tuesday, 22 March 2011

How to enable /disable a custom button on Application ribbon based on the selection of records in CRM 2011 / EnableRules sample on Application ribbon in CRM 2011 / SelectionCountRule sample in CRM 2011

How to place a custom button on Application ribbon in CRM 2011
Reference :http://crmdm.blogspot.com/2011/02/how-to-place-custom-button-on-main-page.html


Lets  consider a scenario where we have a custom button on the Application ribbon and we would like to enable it only when the user selectes minumum 2 records. This requirement could be attained by using <EnableRules> in the customizations.xml.
Lets try by creating a New solution. For detailed steps please refer the first link.
Before exporting add the Application ribbon component to the Solution as shown below.





After this step, export the solution and then extract it to open the customizations.xml.


Lets modify the customizations.xml in such a way that we would place a button and that button will be enabled only when the user selects a minimum of 2 records.


EnableRule could be defined under the ruledefinitions tag as shown.
Here we have chosen one of the enable rules namely, SelectionCountRule. As the name indicates, this enables a button based on the count of the records selected. In this case we have defined the minimum as 2 and maximum as 50. The button will be enabled only if we choose at least 2 records.
 <SelectionCountRule AppliesTo="SelectedEntity" Minimum="2" Maximum="50"></SelectionCountRule>


So when we import the customizations.xml, we would get a disabled button as shown below.

Please note 2 important points. 1. There is a button namely AlfaPeople on the Application ribbon but its disabled 2. There are no records chosen by the user.

So lets create 2 Account records and test the same. As you could see, the button gets enabled when we choose atleast 2 records. If you click on the button it will navigate to our company website.




Code snippet:
<ImportExportXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Entities></Entities>
  <Roles></Roles>
  <Workflows></Workflows>
  <FieldSecurityProfiles></FieldSecurityProfiles>
  <Templates />
  <RibbonDiffXml>
    <CustomActions>
<CustomAction Id="myAction" Sequence="41"
        Location="Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab.Workflow.Controls._children">
       <CommandUIDefinition>
<Button Id="myButton" TemplateAlias="o1" LabelText="AlfaPeople" Command="sample.myCommand">
</Button>
       </CommandUIDefinition>
    </CustomAction></CustomActions>
    <Templates>
      <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
    </Templates>
<CommandDefinitions>
      <CommandDefinition Id="sample.myCommand">
        <EnableRules>
          <EnableRule Id="enableifrecords"></EnableRule>
        </EnableRules><DisplayRules></DisplayRules>
        <Actions>
          <Url Address="http://www.alfapeople.com"></Url>
        </Actions>
      </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
      <TabDisplayRules />
      <DisplayRules />
      <EnableRules>
        <EnableRule Id="enableifrecords">
          <SelectionCountRule AppliesTo="SelectedEntity" Minimum="2"                    Maximum="50">
          </SelectionCountRule>
        </EnableRule>
      </EnableRules>
    </RuleDefinitions>
    <LocLabels />
  </RibbonDiffXml>
  <EntityMaps />
  <EntityRelationships />
  <OrganizationSettings>
    <customization>
      <isappmode>False</isappmode>
    </customization>
  </OrganizationSettings>
  <optionsets />
  <Languages>
    <Language>1033</Language>
  </Languages>
</ImportExportXml>

 


1 comment:

  1. it is really awesome to discover your site on the web as it really those ones who are just starting to explore the topic it services company

    ReplyDelete