Views:
Applies to Product - Power Pages

What’s happening?
The security is not being applied properly in Power Pages using table permission, which is causing incorrect results when performing an aggregation using FetchXML web template. Specifically, when using the aggregate parameter in FetchXML queries, the same records are counted multiple times, leading to inflated aggregation results.

Reason:
This arises from inconsistencies in the results returned by a web API when using the aggregate parameter in FetchXML queries. The generated code added to the FetchXML is causing the returned records used by the FetchXML's aggregate to multiply.

Resolution:
To resolve this, adjust the FetchXML query by moving the filter condition inside the linked entity. This adjustment ensures that the filtering is applied correctly, preventing the multiplication of records in the aggregation. Below are examples of the FetchXML queries:
Incorrect FetchXML (returns inflated values): xml <fetch mapping="logical" aggregate="true" distinct="true" entity name="xrm_premiumoption"> <attribute name="xrm_priceprorated" alias="subtotal" aggregate="sum" /> <attribute name="xrm_taxamount" alias="taxamount" aggregate="sum" /> <attribute name="xrm_taxrate" alias="taxrate" aggregate="max" /> <filter type="and"> <condition attribute="createdon" operator="le" /> <condition attribute="xrm_isselected" operator="eq" /> <condition attribute="xrm_productfamily" operator="eq" /> </filter> <link-entity name="xrm_application" from="xrm_applicationid" to="xrm_applicationid" alias="allapps" link-type="inner"> <filter type="or"> <condition attribute="xrm_applicationid" operator="eq" /> <condition attribute="statuscode" operator="ne" /> </filter> </link-entity> </fetch>
Correct FetchXML (returns accurate values): xml <fetch mapping="logical" aggregate="true" distinct="true" entity name="xrm_premiumoption"> <attribute name="xrm_priceprorated" alias="subtotal" aggregate="sum" /> <attribute name="xrm_taxamount" alias="taxamount" aggregate="sum" /> <attribute name="xrm_taxrate" alias="taxrate" aggregate="max" /> <filter type="and"> <condition attribute="createdon" operator="le" /> <condition attribute="xrm_isselected" operator="eq" /> <condition attribute="xrm_productfamily" operator="eq" /> </filter> <link-entity name="xrm_application" from="xrm_applicationid" to="xrm_applicationid" alias="allapps" link-type="inner"> <filter type="or"> <condition attribute="xrm_applicationid" operator="eq" /> <condition attribute="statuscode" operator="ne" /> </filter> </link-entity> </fetch>