Recently we had a requirement to filter sub grid on one of the forms. We thought of using Plugin on Retrieve Multiple for this.
Here we were showing Opportunity Sub Grid on Account form.
So we created a view for Opportunity that will be used as Sub Grid. Used it as Related Record Sub Grid so that we can have the GUID of the Account record being passed to the plugin.
The problem we faced à Sorting and Paging stopped working for the Sub Grid.
http://crmtipoftheday.com/2015/10/05/limitations-of-retrieve-plugins/v
</p> <p>void IPlugin.Execute(IServiceProvider serviceProvider)<br /> {<br /> // Obtain the execution context from the service provider.<br /> IPluginExecutionContext context = (IPluginExecutionContext)<br /> serviceProvider.GetService(typeof(IPluginExecutionContext));</p> <p>// Obtain the organization service reference.<br /> IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));<br /> IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);</p> <p>// The InputParameters collection contains all the data passed in the message request.<br /> if (context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression && context.MessageName == "RetrieveMultiple")<br /> {<br /> QueryExpression qe = (QueryExpression)context.InputParameters["Query"];<br /> if (qe.EntityName == "opportunity")<br /> {<br /> string currentCustomerId = string.Empty;<br /> ConditionExpression[] filters = qe.Criteria.Conditions.ToArray();<br /> foreach (var filter in filters)<br /> {<br /> currentCustomerId = filter.Values[0].ToString();<br /> }</p> <p>FetchXmlToQueryExpressionRequest req = new FetchXmlToQueryExpressionRequest();<br /> req.FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +<br /> "<entity name='opportunity'>" +<br /> " <attribute name='name' />" +<br /> "<attribute name='customerid' />" +<br /> "<attribute name='estimatedvalue' />" +<br /> "<attribute name='statuscode' />" +<br /> "<attribute name='opportunityid' />" +<br /> "<order attribute='name' descending='false' />" +<br /> "<link-entity name='account' from='accountid' to='parentaccountid' alias='ad'>" +<br /> " <filter type='and'>" +<br /> " <filter type='or'>" +<br /> " <condition attribute='accountid' operator='eq' uiname='aaass' uitype='account' value=' " + currentCustomerId + "' />" +<br /> " <condition attribute='accountid' operator='under' uiname='aaass' uitype='account' value='" + currentCustomerId + "' />" +<br /> "</filter>" +<br /> "</filter>" +<br /> "</link-entity>" +<br /> "</entity>" +<br /> "</fetch>";<br /> FetchXmlToQueryExpressionResponse resp = (FetchXmlToQueryExpressionResponse)service.Execute(req);<br /> context.InputParameters["Query"] = resp.Query;</p> <p>}<br /> }</p> <p>
Hope it helps..
Had a post wrote about the same subject that I published too. It is very usefull that type of data manipulation in some cases.
Cheers
LikeLike
miguel where do i find your post?
LikeLike
Maybe it is late but here it goes: https://migsbeja.wordpress.com/2016/04/21/retrieve-multiple-plugin/
LikeLike
Reblogged this on Passion Dynamics and commented:
Filter Subgrid Records Using A Plugin
LikeLike
I have added some columns in a Filter Expression I added in my retrieve multiple plugin. Checking the FetchXML created and running it in XRMToolBox shows the Filter Expressions have been added all columns correctly displaying. Checking the ColumnSet.Columns.Count shows the correct number of Columns.
HOWEVER, the output on the grid produced by Advanced Find does not show the columns I added in the plugin. It seems we need to update the “grid” XML or something. Have you figured out how to do this?
clint
LikeLike
Did you get the answer to this?
LikeLike
When is this plugin added? For what stage? Pre-operation or Post-operation?
LikeLike
from where does critiria.conditions are coming from? where did you add your conditions? in plugin?
LikeLike