How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

Using Enable Rules in Dynamics 365 with the Ribbon Workbench
By Adam Murchison

Using the Ribbon Workbench made by Scott Durow facilitates editing and adding additional features to the Ribbon within Microsoft Dynamics 365. This blog will provide simple tips and tricks specifically with the enable rules in the creation of buttons.

Knowing Where to Enable Your Button

When creating a button, it is highly important to think about when you would like to enable this button. This is important because users will click a button on the form regardless whether it was supposed to be clicked or not. For example, the functionality of the button may be using data from fields on the form so it would make sense to enable the button after the record has been created and when the specified field(s) are populated with the appropriate values.

I will provide one example of a button and its enable rules, this button changes an events status to complete. There are two simple requirements for this button; that the event status is not already Completed or Cancelled and that the event is not in the create form because you can’t complete an event until it exists.

Understanding Each Component of this Enable Rule

Here is the simple rule that I used to disable the button when the event is being created.

image thumb 7 How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

The Un-customised (IsCore) property is used to indicate if you are writing a custom command or using an existing command in CRM. Set to false if you are using a custom command for the button and set to true if you want to reference the enable rule within your solution without customising it.

The FormStateRule above is a step that has been added to validate that the form is not in a ‘Create’ state. The default field is used to specify whether the default value of the rule is true or false and the invertresult field is used to invert the result of the rule. In this case the FormStateRule is set at false to begin with and if the State is in a ‘Create’ state then the rule will be evaluated as true. We want to disable the button when the form is in a ‘Create’ state so we invert the result.

Below is the second rule I applied to the button, this one checks that the state of the record is not already ‘Completed’ or in the state ‘Cancelled’. We are evaluating a value within the form, in this case the statuscode, so we use a ValueRule. The default value of this rule is true and when the statuscode is equal to ‘Completed’ (809730000) or ‘Cancelled’ (809730001) this evaluates to true also. We want the button to be disabled when both these conditions are met so we invert the result.

image thumb 8 How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

image thumb 4 How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

Below is the create page for a new event, if the button “Complete” was enabled here then the logic to change the event to complete would not make sense because the event has to exist before changing the status to complete.

image thumb 2 How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

Potential Reasons Why Your Button Isn’t Showing Up

An important thing to remember is to add the enable rule(s) to the command. This is commonly missed, someone creates an enable rule but forgets to add it to the button command. This can be achieved easily as shown in the image below.

image thumb 10 How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

If you forget to add enable rules to the command then the button will show on all states/stages of the form. If you forget to add the command to the button, then the button will not show up on the form.

image thumb 9 How to Use Enable Rules in Dynamics 365 with the Ribbon Workbench

Let’s block ads! (Why?)

Magnetism Solutions Dynamics CRM Blog