Ribbon customization can be done using Ribbon Workbench.

In Ribbon Workbench window, select entity that will have dynamically loaded ribbon, and add new Rule.

When adding new rule, choose Value Rule.

CRM_value_rule

This rule should be associated to the Command and to the Button that triggers that command.

InvertResult of False is True, so the rule above means that the button will be loaded when the value of the field new_subject is “Hello World”.

You can add multiple value rules, or you can make a combination of rules, and define that some button will be displayed if one OR another condition or group of conditions is met.

CRM_OrRules

In order for our button to be loaded dynamically, it is necessary to create new web resource (JavaScript) and to add following code:

function refreshRibbonOnFieldChange()
{
Xrm.Page.ui.refreshRibbon();
}

refreshRibbon is predefined Xrm.Page.ui method that causes ribbon to re-evaluate data that controls what is displayed in it.

The only thing left to do is to add newly created JavaScript resource to the OnChange event of the form.

CRM_onLoad

After saving and publishing changes, defined Ribbon Button will be displayed only if the condition is met.