Configuring Quick Find to search in the related entities

By | July 25, 2017

This is a continuation of the original Quick Find on Your Terms post – I am going to walk you through the configuration steps using the scenario described in that original post.

However, before we continue, you may want to have a look at yet another post that explains how we can use entityname attribute in FetchXml: Two Most Ignored Features of FetchXml

So, again, let’s say we wanted Quick Find on the contact entity to return any contacts where:

  • The keyword occurs in the FullName attribute
  • Or the keyword occurs in the the parent account’s name
  • Or the keyword occurs in the grand-parent account’s name (parent account of the parent account)
  • Or the keyword occurs in the associated opportunity’s title

Once translated into FetchXml, here is what we are trying to do:


<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="contact">
    <attribute name="fullname" />
    <attribute name="parentcustomerid" />
    <attribute name="address1_city" />
    <attribute name="address1_telephone1" />
    <attribute name="telephone1" />
    <attribute name="emailaddress1" />
    <attribute name="contactid" />
    <attribute name="processid" />
    <attribute name="fullname" />
    <attribute name="parentcustomerid" />
    <attribute name="address1_city" />
    <attribute name="address1_telephone1" />
    <attribute name="telephone1" />
    <attribute name="emailaddress1" />

    <order attribute="fullname" descending="false" />
    <filter type="or">
      <condition attribute="fullname" operator="like" value="#keyword#" />
      <condition attribute="name" entityname="aa" operator="like" value="#keyword#" />
      <condition attribute="name" entityname="opp" operator="like" value="#keyword#" />
      <condition attribute="name" entityname="grandParentAccount" operator="like" value="#keyword#" />
     </filter>
    <link-entity name="account" from="accountid" to="parentcustomerid" alias="aa" link-type="outer">
    </link-entity>
    <link-entity name="account" from="accountid" to="parentcustomerid" alias="a1" link-type="outer">
      <link-entity name="account" from="accountid" to="parentaccountid" alias="grandParentAccount" link-type="outer">
      </link-entity>
    </link-entity>
    <link-entity name="opportunity" from="parentcontactid" to="contactid" alias="opp" link-type="outer">
    </link-entity>
  </entity>
</fetch>

Here is a quick explanation:

  • There are a few linked entities: account, grandparent account, and opportunity
  • There is an “OR” filter which is instructing Dynamics to search for the #keyword# (we’ll get to that shortly) in the attributes we decided to search on
  • And, finally, this fetch is configured to return a number of attributes

If we were able to replace whatever query Quick Find is using with this FetchXml so that #keyword# was also replaced with the search test.. Quick Find would work just the way we wanted it to work.

This is where you can use TCS Tools solution:

1. Prepare your FetchXml

  • Use that FetchXml above as an example
  • If you are doing it for the Contact entity (you can do it for other entities as well), make sure this FetchXml returns all the attributes which are listed in the Quick Find view for that entity (go to Dynamics, have a look at the columns, add those columns AND contactid (or other entity id) column. This is important. Again, this FetchXml has to be prepared so that it returns the same columns which are listed in the Quick Find view
  • You can add more filters and/or linked entities if you want – if you put #keyword# tag anywhere in that fetch, it’ll be replaced with the search string automatically once it’s all been configured

2. Create a TCS Quick Find record for the contact entity (or for whatever entity you have been setting up)

Put entity name in the Entity Name field (contact, account, new_testentity, etc..)

Then paste your Fetch Xml into the Fetch Xml field.

And save that record..

That’s it – you can, now, go to the list of Contacts in Dynamics and try your new Quick Find functionality.

There are a few things to keep in mind:

  • As you keep adding more filters, the search is becoming more complex. Eventually, that may become a performance issue
  • When you create that record above, a RetrieveMultiple plugin step will be registered on the pre-retrieve of your entity. All the “magic” will be happening in that plugin, really (in short, it will be replacing default Quick Find query with your own Fetch Xml)
  • This solution will not allow you to create multiple TCS Quick Find records for the same entity (which would not make sense really)
  • If you wanted to disable this feature for a particular entity, you can simply delete TCS Quick Find record for that entity

There is a known bug in the 1.0.0.5 version of the TCS Tools: you won’t be able to order Quick Find search results by clicking on the column header. That’s not a platform limitation, but I need to change a few things in the plugin to make it work, so that’ll be v 1.0.0.6 I guess.

Update(Jul 26, 2017): you can download v1.0.0.6 now – sorting should be working there (or in whatever later version that’s available when you are reading this). 

 

4 thoughts on “Configuring Quick Find to search in the related entities

  1. Fbrem

    Hey Alex,
    this is amazing, it works in lookup fields by design as well! Great stuff, thanks a lot!

    Reply
  2. Zane

    Hello

    This did not work for me in Dynamics 365 (online). I followed all the steps and no search results were returned in Quick Find.

    I am trying to search on customer number under a related record type.

    Reply
  3. sam

    Hi! This is great but i just couldnt get it to work 🙁 Is there any other tutorial/ Step-by-step somewhere?

    BR
    Sam

    Reply
  4. Ali Rahmanifard

    Hi,
    When I’m trying to save a tcs_quickfind record, I get an error. The log is here:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Custom SdkMessageProcessingStep is not allowed on the specified message and entity.Detail:

    869f29bd-0bff-4120-bd14-b61b7c7b9397
    -2147204729

    Custom SdkMessageProcessingStep is not allowed on the specified message and entity.
    2021-05-08T21:35:36.0815682Z
    false

    [TreeCatSoftware.Dynamics.TCSTools: TreeCatSoftware.Dynamics.TCSTools.Plugins.QuickFindUniqueNamePlugin]
    [e402ea82-bf70-e711-8113-480fcfea20c1: TreeCatSoftware.Dynamics.TCSTools.Plugins.QuickFindUniqueNamePlugin: Create of tcs_quickfind]

    Can anyone help me?!
    Thanks.

    Reply

Leave a Reply to Zane Cancel reply

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