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
}