As part of June 2019 updates, new feature was introduced where you can select CDS view as a filter on entities. This is helpful and great way to retrieve filtered records as filter is applied on server side instead of retrieving records (2000 at a time) first and then apply filter locally. Refer blog for more details. This new feature is in preview and can be enabled from Advanced Settings as shown below:
As part of this blog we will see how we can use CDS views as filter to overcome Delegation limitation.
- I am using Gallery control and have set Items property as below to retrieve Incidents created in last 180 days
Filter(Incidents, ‘Created On’ >= Today()-180)
- I have added label and have set Text property as below to show count of records in Gallery control
“Count: ” & CountRows(Gallery2.AllItems)
- You will observe delegation warning here as shown below. Also, you can see count is 287.
Point to note down here is count of records in Gallery which is 287 but its more than that when using same filters in CDS/Dynamics 365 for Incident entity. Reason is first 2000 records are retrieved first and then filter is applied locally ending up with 287 records. Let’s use CDS view as filter and try to accomplish same.
- I have created a CDS view “Incidents Created in Last 180 Days” in PowerApps web portal with same filter on CreatedOn used above
- I have created a Collection for Incidents entity using filter as CDS view created above using below formula. You can add this formula either on App Start or OnLoad of your screen
ClearCollect(incidentsCollection,Filter(Incidents, ‘Incidents (Views)’.’Incidents Created in Last X Days’))
- I have added another Gallery control on form with Items property set to “incidentsCollection” and another label to show count of records in Gallery 2.
- As you see below Count is 2000 now which is max number of records retrieved at a time but definitely more than what we retrieved without using CDS View.
You can also select View from properties bar on right side for any control once Data Source is selected as CDS Entity.