Monday, December 10, 2018

Append search column(s) in Quick Find View - Microsoft Dynamics 365

In Microsoft Dynamics 365, Quick find allows you to search record(s) on an entity. You can configure view and find columns in quick find view. You can add columns from the entity on which the the quick view is created.You can not add search columns of other related entities. If the requirement is to show matching contacts based on related entity search, then OOTB view customization will not allow you to do this.

In given ER diagram "Contact"and "Subscription" have N:N relationship through an intersection entity "ContactSubscription".

Records in Contact, Subscription and ContactSubscription entity

Contact Entity
Subscription Entity
NameNetFlixHBO GOPrimeHotStar
ContactSubscription Entity
ContactAbhishek KumarAbhishek KumarAbhishek KumarAlex Goldwin
SubscriptionNetFlixHBO GOPrimeNetFlix

In above table structure "Abhishek" have three subscriptions "NetFlix", "HBO GO" and "Prime" and "Alex" has one subscription "NetFlix".

In quick view we would not include subscription on contact grid search. If we do a search on keyword "NetFlix". We would not get any record.

The requirement is to search/show all the contacts based on there active subscriptions. E.g. for "NetFlix" it should show two records "Abhishek" and "Alex", for "HBO GO" and "Prime" it should show one contact "Abhishek".

Before we go on implementation its better to know that how CRM executes the Quickfind view? Internally CRM creates a query expression contains view and search columns with isquickfindfields property set true in filter condition. If you convert Queryexpression to FetchExpression the XML would look like as given below. You can extract Queryexpression by profiling Plugin on ReteriveMultiple step.

If we add conditions by manipulating the request in RetrieveMultiple Plugin, that would accomplish the requirement. Given below the code snippet.

In above code we have first extracted the contacts that have subscription provided in search string.
FetchExpression fexp = new FetchExpression("FetchXML query to get contact(s) on subscription(s)");
EntityCollection ecollection = service.RetrieveMultiple(fexp);

The resultant is then added to the search condition isquickfindfields criteria, which will return contacts matched with provided contactid.

foreach (Entity ent in ecollection.Entities)
  ConditionExpression cexpression = new ConditionExpression();
  cexpression.AttributeName = "contactid";
  cexpression.Operator = ConditionOperator.Equal;

Plugin Registration

Quick find Search for "NetFlix" subscription.

Quick find Search for "Prime" subscription.

No comments:

Post a Comment