FetchXML: get count of records based on a field of a linked entity

安稳与你 提交于 2019-12-22 12:08:12

问题


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>

回答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>



回答2:


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>


来源:https://stackoverflow.com/questions/24118774/fetchxml-get-count-of-records-based-on-a-field-of-a-linked-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!