I am using this tutorial to create a FetchXML plugin: https://msdn.microsoft.com/en-us/library/gg309565.aspx
The plugin has the fetchXML string hardcoded:
string estimatedvalue_avg = @"<fetch distinct='false' mapping='logical' aggregate='true'><entity name='opportunity'><attribute name='estimatedvalue' alias='estimatedvalue_avg' aggregate='avg' /></entity></fetch>";
What I have done is create a textarea in CRM, called "new_fetchXML" in the Account entity. The User puts the EXACT fetchXML query in my textarea:
<fetch distinct='false' mapping='logical' aggregate='true'><entity name='opportunity'><attribute name='estimatedvalue' alias='estimatedvalue_avg' aggregate='avg' /></entity></fetch>"
But, it's failing. It gives me a platform error.
In my plugin, I have the following:
string query = (string)entity["new_fetchXML"];
EntityCollection estimatedvalue_avg_result = _serviceProxy.RetrieveMultiple(new FetchExpression(query));
Just to be clear - I know how to create a plugin, the query works when I follow it; it's just that I cannot put the query in a CRM textarea and have it execute.
When I run the debugger, I see that the value inside the query variable is badly formatted.
Does anyone have any snippets, suggestions?
Thanks.