Show/Hide Ribbon Button using Enable Rule

If you want to show/hide a ribbon button, but you are having problems because of the load/save events that sometimes makes the show/hide not work correctly, this is the best way I found to get the job done.

Just need to add this bit of code in the RibbonDiffXml in the extracted solution of the entity you want to add (or already have) the button, in the customization.xml file.

<CommandDefinitions>
 <CommandDefinition Id="Mscrm.Form.entity.name"> <!--button id-->
 <EnableRule Id="entity.functionName.EnableRule" />
 <DisplayRules />
 <Actions>
 <JavaScriptFunction FunctionName="markopportunityasgo" Library="$Webresource:cst_Opportunity2013" />
 </Actions>
 </CommandDefinition>
 </CommandDefinitions>

<EnableRules>
 <EnableRule Id="entity.functionName.EnableRule">
 <CustomRule FunctionName="javascriptFunction" Library="$webresource:javascriptFileName">
 <CrmParameter Value="PrimaryItemIds" /> <!--get entity id-->
 </CustomRule>
 </EnableRule>
 </EnableRules>
//Javascript function that get the entity id. If gives error, you can remove it from the funtion
function javascriptFunction(id)
{
 //Logic
 return true; //shows button
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s