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
4. Now import the customization file.
Hope it helps!!!
<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!!!