I would like to conditionally disable a System Ribbon = AddNew in a CRM 2011 form with javascript. That means if the statusCode is X or Y disable the Ribbon, how could I do this?
I tryed to get the ID of the Ribbon in order to change the classname of the Ribbon to disabled, but I got Null because the Ribbons are loaded asychronously!
To expand on Anwar’s answer, the key to getting this to work is to intercept and repurpose the functionality of the
AddNewribbon button, but once you do, there won’t be any need for hacking the Ribbon DOM. Below are a few steps that you can take to get there.1) Create a solution with the Application Ribbon included.
2) Find in the SDK the sample ribbon for the Application Ribbon or build it yourself using the solution included in the SDK.
3) Find in the Application Ribbon template the control you’re interested in, which I assume in this case is the
AddNewbutton in entity subgrids. Repurpose this control in aCustomActionand make the location of theCustomActionthe same name as the control you want to repurpose.4) Find in the Application Ribbon template the definition of the command of this button, and using the exact definition as the basis of a new
CommandDefinition, add in your own custom rule (in this case, a newEnableRule).5) Here is where Anwar’s answer comes in: using both the
OrRuleand theValueRule, define yourEnableRuleto check on thestatuscodes of the entity. The linked demonstration relates to a new ribbon button, but the same rules work for repurposed ribbon controls as well.Publish your changes when you’re done and your ribbon should be all set. Because I’m not sure how familiar you are with
RibbonXml, I’ll also mention that Microsoft has some comprehensive walkthroughs that are pretty helpful (after much time studying them!) in picking it up.