Sometimes we may have a requirement where we do not want to delete the inactive activity. So, to do that we need to show/hide the ribbon button based on status value.
Here you can see in a dynamics community we have a very similar requirement: https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/377941/show-hide-delete-button-on-activities-based-on-state
As per the requirement we need to hide the entire delete button for inactive activity type entity records. But unfortunately, we cannot do this by customizing only one entity. Although the question is pretty obvious as we can see all activity type record in single grid and open each activity type record from the navigation. But you may have seen that when you navigate or click on each activity type entity it’s basically rendering the ribbon of that specific entity.
Email, appointment, phone call etc. all are activity type of entity and they have different ribbon and not the same common activity ribbon. In below screenshot you may get a clear picture what is Activity type of entity.
So, hiding delete the button in Activity entity will not work for you. You need to customize each activity type entity ribbon to hide the button, hiding activity type entity ribbon button is similar to a hide button using ribbon workbench based on condition of any other entity.
Here in this article I will take the Email entity and hide delete button in the form.
When statecode having “completed” status. So, to do that we need to understand that what the state codes available in an entity are. Here you can see we have the statecode is equal 1 for all completed emails with the status reason like Completed, Sent, Received etc. So, I will hide the delete button an email record statecode = 1.
|Status (statecode)||Associated Status Reason (statuscode)|
|0 Open||1 Draft|
|1 Completed||2 Completed|
|6 Pending Send|
|2 Canceled||5 Canceled|
We will use here Ribbon workbench display rule with steps value rule here in this scenario and this is a no-code solution. Here I created a solution and include email entity in that solutions. Take a look below screenshot.
Now open the solution using Ribbon Workbench. Once you open Ribbon workbench find the delete button in the form area. Be careful you can find two buttons so here is the button where you need to include value rule.
As you know this is a managed OOTB button ,so you need to click on “Customize Button” first in below screenshot and then again right click on the button and click on “Customize Command” to modify ribbon.
Next steps we will add a display rule by right click on Display Rule header.
You will find in the right section of the screenshot, give a nice name.
Click on “Add Steps” to add Value Rule.
Here in the below screenshot you can see value Rule section, you will find 4 options there, we need to understand first which options is for what.
This options talk about what will the default behavior for this particular rule, for example we want to hide the button so we have to select false otherwise true.
I think this is one of confusing option, just remember this options is optional but its needed when you have several else part for the value which you sleeted in value rule, for example in our scenario we don’t want to show button only for statecode =1 and for others statecode (1, 2) value we should be display the button so even we set button visibility Default =false in the Value Rule, its basically inverts the result here which is true.
I don’t want to go other two options field and value. Put Field logical name in the field options. Make sure we choose the specific field value by which we are implementing the logic as we don’t have options to select multiple fields in a single value rule.
So, in our case the Value Rule should be look like -
See below screenshot, you need to add the Display Rule to the command and do publish.
Here is the result, I have viewed one Email record with Draft state which means statecode=0 and I can see the button.
Look here for completed Email I cannot see the delete button.
We as a Microsoft Dynamics CRM Services Company like to share such resources! Hope this is useful for you.