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.
1) Using Javascript Code in Custom Javascript Section:
- Get the Order Status value
- Get the ID of the ‘Edit Order’ button.
- Check the Order Status and if its in ‘Draft’ status, then hide the button using javascript/jquery.
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:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="salesorder">
<attribute name="name" />
<attribute name="customerid" />
<attribute name="statuscode" />
<attribute name="totalamount" />
<attribute name="salesorderid" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="new_orderstatus" operator="eq" value="100000003" />
</filter>
</entity>
</fetch>
Step 2: Remove all the attributes and order properties in Fetch XML query
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="salesorder">
<filter type="and">
<condition attribute="new_orderstatus" operator="eq" value="100000003" />
</filter>
</entity>
</fetch>
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.
This is a nice way to customize! I wish they would put the same filter criteria option on the main sub-grid itself.