Nov 24, 2011

Defining EnableRule for buttons

We have discussed how to add custom buttons to ribbons in a recent post. We have used standard Enablerules for them. Enablerules are to define criteria when to enable/disable our button. If we discuss a real time scenario, I need to enable a button in account form ribbon when account is a company. Here, account can be an individual or a company, which decides by the value of one option list.  We will first see the CustomActions and CommandDefinitions entries, which are familiar already.

  <CustomAction Id="CA_CUSTOM_CompanyFunction" 
      <Button Id="B_CUSTOM_CompanyFunction" 
       LabelText="Company Matters" 
       ToolTipTitle="Company related Matters" 
       ToolTipDescription="This calculate and gives you the company related information" 

  <CommandDefinition Id="Cmd_CUSTOM_CompanyFunction">
      <EnableRule Id="ER_CUSTOM_CompanyCustomer" />
      <DisplayRule Id="Mscrm.CanSaveAndClosePrimaryEntityType" />
    <Actions />

Now, take a close look at the enable rule ER_CUSTOM_CompanyCustomer  which is defined by me. This is to be defined with our criteria. Interesting part of ribbon is that I can define those in a special section called <RuleDefinitions>. Under this tag, we can see two sections to define two kinds of rules. Namely Display rules and Enable rules. See carefully, how I have defined my enable rule there.

  <TabDisplayRules />
    <EnableRule Id="ER_CUSTOM_CompanyCustomer">
      <ValueRule Default="false"  

Here mew_typeofcustomer is the name of optionlist and 100000001 Is the value of company.

We didn’t have this kind of controlling power in CRM 4.0. This is cool.
(Read about Displayrules here.)

No comments:

Post a Comment