{"id":109223,"date":"2019-04-05T07:00:32","date_gmt":"2019-04-05T14:00:32","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/delegation-enhancements-for-lookups-today-now-and-addcolumns\/"},"modified":"2024-06-12T18:49:49","modified_gmt":"2024-06-13T01:49:49","slug":"delegation-enhancements-for-lookups-today-now-and-addcolumns","status":"publish","type":"power-apps","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/delegation-enhancements-for-lookups-today-now-and-addcolumns\/","title":{"rendered":"Delegation enhancements for lookups, Today\/Now, and AddColumns"},"content":{"rendered":"
I’m happy to announce we’ve made another batch of delegation enhancements for Canvas apps.<\/p>\n
Delegation refers to an app’s ability to “delegate” work to the data source instead of doing it locally, resulting in more scalable and higher performance apps.\u00a0 In short, Delegation = Good.\u00a0 For more details see\u00a0Understand delegation in a canvas app<\/a>.<\/p>\n We are far from done with delegation.\u00a0 If you have suggestions on which queries and operations we should improve next please leave a comment or use the community forum<\/a>.<\/p>\n This one is specific to the Common Data Service.\u00a0 Until now we have only supported filtering an entity based on the primary key of a Many-to-One lookup.\u00a0 We can now filter based on other fields in the related entity, dramatically expanding the possibilities when working with lookups.<\/p>\n For example, consider the following screen, built on top of the standard Accounts and Contacts entities:<\/p>\n Note that there are no blue wavy lines or warning symbols – this formula is fully delagable.\u00a0 Let’s type a value in the text input box to perform our filtering:<\/p>\n If we watch the network traffic from our app, and URL decode the query,\u00a0we see:<\/p>\n This is OData<\/a> speak for the formula we wrote with “primarycontactid” and “address1_city” being the logical names for our entity and column references in the formula.\u00a0 The IsBlank<\/strong><\/a> test does not appear here because it does not depend on data in the records being filtered and was handled before talking with the data source.<\/p>\n We can also delegate the StartsWith<\/strong>\u00a0and EndsWith<\/strong><\/a> functions for our search:<\/p>\n But we can’t yet delegate the\u00a0in<\/strong> operator, it is on our to-do list.\u00a0 Although definitely not the same, StartsWith<\/strong> can be used for many scenarios until we can delegate\u00a0in<\/strong>.<\/p>\n Because these Filter<\/strong> calls can now be delegated, we can now search through millions of records and return the first page of results quickly with the ability to go back for more as the user scrolls through them in the gallery.<\/p>\n In the lookup filter example above, the IsBlank<\/strong> test didn’t need to be delegated because it could be evaluated locally before going to the data source.\u00a0 We will be doing more of these optimizations over time.<\/p>\n Case in point: we just added the Today<\/a><\/strong> and Now<\/a><\/strong> functions to the list of things we can do locally.\u00a0 For example, this filter of the Accounts entity:<\/p>\n expands the Today function call into a constant to send to the data source:<\/p>\n Similarly, we already supported delegation for the Date<\/a> function:<\/p>\n But, we don’t yet support constant folding with the DateAdd<\/a> function:<\/p>\n We’re on it.<\/p>\nFilter on lookup non-primary key fields<\/h2>\n
<\/p>\n
<\/p>\n
$filter=(primarycontactid\/address1_city eq 'Issaquah')&$expand=primarycontactid<\/pre>\n
<\/p>\n
Today and Now<\/h2>\n
<\/p>\n
$filter=createdon ge 2019-04-01T16:16:03.013Z<\/pre>\n
<\/p>\n
<\/p>\n
AddColumns<\/h2>\n