PAB
PAB

Reputation: 51

FetchXML issues with aggregate groupby on an option field

I am having issues with a FetchXML query running against Dynamics CRM 2013 (online).

When running this simple query

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="5">
  <entity name="activitypointer">
    <attribute name="activityid" alias="activity_id" />
    <attribute name="activitytypecode" alias="activity_type" />
    <attribute name="ownerid" alias="owner" />
  </entity>
</fetch>

I get the expected results for the activity_type column e.g. "email", "opportunityclose" etc.

But when I attempt this aggregate version of the same query

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
  <entity name="activitypointer">
    <attribute name="activityid" alias="activity_count" aggregate="count" />
    <attribute name="activitytypecode" alias="activity_type" groupby="true" />
    <attribute name="ownerid" alias="owner" groupby="true" />
  </entity>
</fetch>

I get the correct results for the activity_count and owner columns, but the "activity_type" column is populated with just "Microsoft.Xrm.Sdk.OptionSetValue" or if ran within a report "#error".

I assume this is something to do with grouping by an option field type.

Does anyone know how to resolve this issue?

Upvotes: 0

Views: 1770

Answers (1)

Daryl
Daryl

Reputation: 18895

You have to be very careful when it comes with nulls and grouping. Try adding a filter that excludes null values. I have verified in 2011 that it does return a valid value for Option Sets.

Upvotes: 1

Related Questions