Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal - Netwoven
Blog

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

By Gayathri Selvamani  |  Published on June 19, 2018

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

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:

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal
<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.

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

Select the ‘Entity List’ record for ‘Orders’ page. To define Actions we need to go to Options tab ->Grid Configuration

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

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.

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

We have pasted the ‘Fetch XML’ query updated in step 2 for ‘Filter Criteria’.

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

If ‘Filter Criteria’ property is not displayed by default, then click on ‘Advanced Settings’. It will show all the settings for an Action button.

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

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.

Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal

‘Edit Order’ Menu will be hidden for all other Order Status.

1 comment

  1. This is a nice way to customize! I wish they would put the same filter criteria option on the main sub-grid itself.

Leave a comment

Your email address will not be published. Required fields are marked *

Unravel The Complex
Stay Connected

Subscribe and receive the latest insights

Netwoven Inc. - Microsoft Solutions Partner

Get involved by tagging Netwoven experiences using our official hashtag #UnravelTheComplex