问题
I want to be able to perform a FetchXML request that sums a value while grouping on a field that is a custom option set but I don't get the expected results.
All that is returned is the summed up values, not the related custom option set value that it relates to so I have no idea what the returned values relate to.
This is the fetchXML request which appears to be correct:
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='opportunity'>
<attribute name='estimatedvalue' alias='opportunity_sum' aggregate='sum' />
<attribute name='koo_opportunitytype' alias='koo_opportunitytype' groupby='true' />
</entity>
</fetch>
Each value that is returned only has 1 attribute...the opportunity_sum value.
If I group by say, customer id, then the returned values are summed up correctly and a reference is returned to the related customer for each summed value which is what I would expect.
Is it not possible to group by a custom option set value? This seems to work fine with standard system option set values such as status code.
回答1:
I have verified that your fetch xml works just fine as long as the data is clean. If all of your koo_opportunitytype
values for opportunities are null, it will not return an attribute for them. I'm assuming that you're only getting one entity returned? Also if any estimated value is null for a group, the sum will not be returned either. This means you'll probably want to add a filter to exclude null values from your sum.
来源:https://stackoverflow.com/questions/15490429/crm-2011-performing-fetchxml-group-by-on-custom-option-set-value