Retrieve the number of hierarchically related child records
On the new version of CRM 2015 we came across the hierarchy. This feature is quite nice if you what to get data (in this case the count of child records) from a child with out using several QueryExpression.
Use the rowaggregate attribute in a FetchXML based query to retrieve the number of hierarchically related child records. When this value is set to CountChildren a value that includes the total number of child records for the record is included in the EntityCollection. For example, the following query will include an AccountChildren aggregate value representing the number of child account records in the hierarchical relationship where the {0}
parameter represents the AccountId of the parent record.
<fetch distinct='false' no-lock='false' mapping='logical'> <entity name='account'> <attribute name='name' /> <attribute name='accountid' /> <attribute name='accountid' rowaggregate='CountChildren' alias='AccountChildren'/> <filter type='and'> <condition attribute='accountid' operator='under' value='{0}' /> </filter> </entity> </fetch>
Comments
Post a Comment