Saturday, July 21, 2012

Conditionally Hiding OOB Ribbon Button in CRM 2011

Hi All, To hide the OOB Ribbon button permanently you can use my earlier post. But sometimes we needs to hide OOB Ribbon button conditionally in CRM 2011.  Here I am going to hide OOB "Assign" button conditionally based on Optionset Value.

       On the Account form, if the "Category"  optionset value is "Preferred Customer" then display the "Assign" button otherwise hide the "Assign" button.



1. Export the solution and open Customization.XML file in edit mode. Find the <RibbonDiffXml> at the Account form level.





2. Now open Accountribbon.xml file from the SDK and find the Assign button details at form Level

      
 Now copy the Assign button element from here and add this to custom Actions in the <RibbonDiffXML> which we are customizing.
 we also needs to copy the CommandDefinition of the OOB Assign button to provide OOB assign functionality. otherwise OOB Asign button functionality might not work.

3. Now edit the Account <RibbonDiffXML> in the following way

 <RibbonDiffXml>
        <CustomActions>
          <!-- Location will be ID of the Button-->
          <CustomAction Location="Mscrm.Form.account.Assign" Id="Sample.Form.account.HideAssign">
            <CommandUIDefinition>
              <!-- copy the OOB Asign button CommandUI Definition-->
              <Button Id="Mscrm.Form.account.Assign" ToolTipTitle="$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign" ToolTipDescription="$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Assign" Command="Mscrm.AssignPrimaryRecord" Sequence="33" LabelText="$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign" Alt="$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign" Image16by16="/_imgs/ribbon/Assign_16.png" Image32by32="/_imgs/ribbon/Assign_32.png" TemplateAlias="o1" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <!-- copy the OOB Asign button Command Definition-->
          <CommandDefinition Id="Mscrm.AssignPrimaryRecord">
            <EnableRules>
              <EnableRule Id="Mscrm.FormStateNotNew" />
              <EnableRule Id="Mscrm.AssignPrimaryPermission" />
              <EnableRule Id="Mscrm.NotOffline" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Mscrm.AssignPrimaryPermission" />
              <DisplayRule Id="Mscrm.NotClosedActivity" />
              <!-- Add new display Rule for conditionally hiding-->
              <DisplayRule Id="Sample.Form.account.HideAssign.DisplayRule"/>
            </DisplayRules>
            <Actions>
              <JavaScriptFunction FunctionName="assignObject" Library="/_static/_forms/form.js">
                <CrmParameter Value="PrimaryEntityTypeCode" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules>
            <!--Define the conditional Hiding Display Rule-->
            <DisplayRule Id="Sample.Form.account.HideAssign.DisplayRule">              
              <ValueRule Field="accountcategorycode" Value="1"/>
              <!--Field will be CRM field schema Name, Value will be optionset Value-->
            </DisplayRule>
          </DisplayRules>
          <EnableRules />
        </RuleDefinitions>
        <LocLabels />
      </RibbonDiffXml>
 

4. Now import the customization file.

Hope it helps!!!

2 comments:

  1. Thank you very much prasad ,its working very well,thanks for sharing . here are more tips and information. Microsoft Dynamics CRM

    ReplyDelete
  2. I am curious since you are discovering buttons. I am completely new to this and I am wondering if it is possible how to place an assign button on a the ribbon when in the queues entity? My goal is to select multiple trades or emails etc, and assign to a specific user. I do not see a way to do this. I hear a people saying things about plugins, and I have workbench ribbon however I can't seem to figure this out.. Any good reference guides or guidance? Thanks a lot!

    ReplyDelete