3370 Views
3 minutes read
Categories
Dynamics 365

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.

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

About Gayathri Selvamani

Gayathri has around 10+ years of extensive experience in Microsoft Dynamics CRM 2011/2013/2015 and SSIS, SSRS, C#.Net, ASP.NET with SQL Server, in development of applications using Microsoft Dynamics CRM and Microsoft Business Intelligence Development with an Enterprise support. In addition, she is conversant with Agile Scrum Methodology for the development of the application and Versioning control tolls like VSS, SVN, and TFS. Also, extended experience in using CRM Web Services/WCF interface and exposing organizational data and writing LINQ based queries to perform CRUD operations. Prior to joining Netwoven, she was working with Positive Edge Technology Limited, Bangalore as Technical Lead and Infosys Limited, Chennai.

Gayathri did her B Tech (Information Technology) from Bharathidasan University in the year 2003. She has completed Certifications in MSCRM 2013 Customization and Configuration and Developing ASP.net applications with C#.

A native of Tamil Nadu, she is presently living in Bangalore. During her leisure time, she loves listening music, watching movies and spending time with her family.

LinkedinTwitterFacebook

1 reply on “Using Fetch XML Based Filter Criteria to Show/Hide Action Buttons in a Dynamics 365 Online Portal”

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 Reply

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