What is stopping you to use out of the box SubGrid in Dynamics 365?
As you know that Dynamics CRM SubGrid is always show the related data and based on the views (with filter criteria) which we set in the SubGrid properties window.
Sometimes we may want to add additional filter to retrieve the data based on some dynamics value on top of OOTB related data. You can add additional filter in the OOTB view filter condition but in the view filter condition there is a limitation that you cannot set condition like below –
ProductName= “Some Dynamics Value”.
There is an easiest way which we can do using unsupported way but recently I saw in the community that this is no more working in Dynamics 365 Unified Interface.
var SubgridControl = document.getElementById(“Subscriptions”);
SubgridControl.control.SetParameter(“fetchXml”, fetchXmlquery); // Here fetchXmlquery is custom fetch XML with the filter.
So what should you do? we may also want to filter SubGrid data based on custom filter, let say you want to show data based on login user information . Another scenario like if you want to display SubGrid exists in another entity.
Here I want to share with you, what are the available options by which you can add your custom filter to show data inside OOTB SubGrid instead of custom HTML gird. When you are using custom HTML, you may face many complexities like sorting, binding data, maintaining column fields etc.
Scenario 1:
Show integrated system data in a SubGrid for a contacts at real time.
If you are using Dynamics CRM online or on premise V 9.x. You should use Virtual entity, to know more using virtual entity, please refer below –
Create and Edit Virtual Entity
If you are using lower version of dynamics 365 (below 9.x) on premise, you may follow below steps.
- Create an entity in Dynamics CRM which you want to display as SubGrid.
- Crate a batch application which will communicate with integrated system and sync data into CRM certain interval. Or you might be expose some API which can consume your integrated system to push the data in the subgrid entity.
- Create a lookup with in the contact entity related to the SubGrid entity.
- Display the entity as a SubGrid in the contacts forms.
If you are using lower version (below 9.x) of Dynamics CRM online and on premise below solution will work both the case.
- Create your SubGrid entity.
- Create retrieve multiple plugin register in pre-operation of the SubGrid entity.
- Inside plugin consume integrated Systems API and get the data.
- Push the data into Dynamics CRM using Upsert method.
Retrieve Multiple Plugin with filter
Scenario 2:
You want display data based on login user information, let say login user City, Country or may be based on some custom fields.
In this scenario no matter whether you are using Online or On premise, you can use retrieve multiple plugin shared above link to filter the SubGrid data. Inside plugin you will get the calling user id from plugin execution context properties (InitiatingUserId). Once you get the User Id you will easily get the login user information to add the additional condition in the retrieve multiple Query to retrieve filter data for the SubGrid.
Scenario 3:
When you want to show data based on lookup value selected in the forms.
Let’s have an example you have a product lookup in the entity where you want to display your SubGrid and you want to show all products items in a SubGrid. To do this you can follow below steps-
– Create a quick view forms in the product entity.
– Add the product items entity SubGrid in the quick view forms of product.
– Include the quick view forms in which entity you want to display SubGrid. You should have product lookup there in this entity.
– Now on change the lookup value quick view form will render related product items in the SubGrid.
Hope this helps. Please share your comments if you have any other suggestions or if you found anything wrong in my article .
This was originally posted here.

Like
Report
*This post is locked for comments