0

I'm trying to get the count of contacts who have activities. I'm retrieving only one attribute in my FetchXML "fullname" with the aggregate function "count" applied on it. I also have a link-entity with ActivityParty to ensure that this contact has data in that table.

My problem is that the returned "fullname"s are not distinct since FetchXML repeats each contact depending on the number of activities he has. I cannot solve this by using "distinct=true" in my fetchXML as the returned "count(fullname)" will always be distinct.

How can I make FetchXML return distinct fullnames before applying count on them ?

Here's my code:

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' aggregate='true'>
              <entity name='contact'>
                <attribute name='fullname' aggregate='count' alias='countcontact' />
                <filter type='and'>
                  <condition attribute='new_lasttouched' operator='null' />
                </filter>
                <link-entity name='activityparty' from='partyid' to='contactid' alias='am'>
                    <filter type='and'>
                    <condition attribute='participationtypemask' operator='in'>
                        <value>4</value>
                        <value>3</value>
                        <value>6</value>
                        <value>5</value>
                        <value>1</value>
                        <value>2</value>
                    </condition>
                    </filter>
                </link-entity>
              </entity>
            </fetch>
user3340627
  • 3,023
  • 6
  • 35
  • 80

1 Answers1

0

Try add "distinct" to attribute tag, like this:

<attribute name='fullname' aggregate='count' alias='countcontact' distinct='true'/>