2

I have a scenario where i want to get the count of people from an Entity who have multiple location address marked as current address in other linked entity.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" aggregate="true">
<entity name="client">
<attribute name="clientid"/>
<attribute name="name"/>
<attribute name="createdon"/>
<order attribute="name" descending="false"/>
<link-entity name="locationadd" from="clientid" to="clientid" alias="aa">
  <attribute name="locationadd" aggregate="countcolumn" />
  <filter type="and">
    <condition attribute="isthiscurrentadd" operator="eq" value="1"/>
  </filter>
  </link-entity>
  </entity>
</fetch>
Neodine
  • 53
  • 1
  • 7
  • 1
    please improve your question, specifying more details and the real names of the entities – Guido Preite Jun 09 '14 at 10:56
  • @GuidoPreite this is the SQL query which i want to convert to Fetchxml. [code] select ifx_name,count(ifx_isthiscurrent) from ifx_client,ifx_locationaddress where ifx_client.ifx_clientid=ifx_locationaddress.ifx_clientid and ifx_isthiscurrent=1 group by ifx_name having count(ifx_isthiscurrent) > 1 [code] – Neodine Jun 13 '14 at 08:14

2 Answers2

1

The answer is

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' aggregate='true'> 
<entity name='client'> 
<attribute name='clientid' alias='PersonName' groupby='true' /> 
<link-entity name='locationadd' from='clientid' to='clientid' alias='aa'> 
<attribute name='isthiscurrentadd' alias='Count' aggregate='count'/> 
<filter type='and'> 
<condition attribute='isthiscurrentadd' operator='eq' value='1'/> 
</filter> 
</link-entity> 
</entity> 
</fetch>
Neodine
  • 53
  • 1
  • 7
0

Try following - this code will return you the number of clients.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" aggregate="true">
<entity name="client">
<attribute name="clientid" aggregate='count' alias='clientscount'/>
<link-entity name="locationadd" from="clientid" to="clientid" alias="aa">
  <attribute name="locationadd" aggregate="countcolumn" />
  <filter type="and">
    <condition attribute="isthiscurrentadd" operator="eq" value="1"/>
  </filter>
  </link-entity>
  </entity>
</fetch>
Andrew Butenko
  • 5,048
  • 1
  • 14
  • 13