Sometimes we do get a requirement to show/hide action buttons in Entity Form/Web Form/ Sub-grid based on some conditions. For example, Client may ask us to Show/Hide ‘Edit Order’ button in the Portal only if the Order Status is ‘Draft’.
We can achieve this in two ways.
- Get the Order Status value
- Get the ID of the ‘Edit Order’ button.
2) Using Filter Configuration in Grid Settings:
The second method, is quite easy using simple configuration within CRM. We can use the ‘Filter Configuration’ in Grid Settings to configure the Action button display.
Here I am going to explain in detail how to show/hide action buttons in ‘Orders’ Entity List Page of Portal based on Order Status.
Step 1: Create the FetchXML query with the Conditions
We can use Advanced Find Query and easily generate the FetchXML from CRM as shown below:
Step 2: Remove all the attributes and order properties in Fetch XML query
Step 3: Configure Grid Configuration settings
Under the Portals tab in Dynamics 365, select the Entity Lists option.
Select the ‘Entity List’ record for ‘Orders’ page. To define Actions we need to go to Options tab ->Grid Configuration
For Edit Action , we need to define an entity form, web page or an URL configured for Edit for Order record.
Below we have selected Target Type as Web Page and ‘Edit Sales Order’ as the Web Page.
We have pasted the ‘Fetch XML’ query updated in step 2 for ‘Filter Criteria’.
If ‘Filter Criteria’ property is not displayed by default, then click on ‘Advanced Settings’. It will show all the settings for an Action button.
Step 4: Test our settings
Log into the portal and then go to the Orders Entity List Page.
‘Edit Order’ Menu will be visible only for Orders in ‘Draft’ status.
‘Edit Order’ Menu will be hidden for all other Order Status.