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".
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 | ||||
Record1 | Record2 | |||
FirstName | Abhishek | Alex | ||
LastName | Kumar | Goldwin | ||
Mobile | 99220 | 32322 | ||
ab@d.com | al@d.com | |||
Subscription Entity | ||||
Record1 | Record2 | Record3 | Record4 | |
SubscriptionType | Paid | Paid | Paid | Free |
Name | NetFlix | HBO GO | Prime | HotStar |
ContactSubscription Entity | ||||
Record1 | Record2 | Record3 | Record4 | |
Contact | Abhishek Kumar | Abhishek Kumar | Abhishek Kumar | Alex Goldwin |
Subscription | NetFlix | HBO GO | Prime | NetFlix |
StartDate | 1-Jan-18 | 1-Jan-18 | 1-Jan-18 | 1-Jan-18 |
EndDate | 31-Dec-19 | 31-Dec-19 | 31-Dec-19 | 31-Dec-19 |
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.
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.
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;
cexpression.Values.Add(ent.Id);
filterexpression.AddCondition(cexpression);
}
Plugin Registration
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;
cexpression.Values.Add(ent.Id);
filterexpression.AddCondition(cexpression);
}
Plugin Registration