Skip to main content

Canvas components can now access app scope directly

Headshot of article author Greg Lindhorst

Canvas components have become an important part of canvas app reuse and scalability.  They enable the sharing of app logic and UI across screens and apps.  They even enable a form of app co-authoring by partitioning an app into pieces that multiple makers can work on at the same time.  You can find some amazing downloadable canvas components at canvas components sample gallery.

And we aren’t done with them yet.  In today’s installment, we are enabling a canvas component to directly access variables, collections, controls, and tabular data sources from its host app.  No longer do you need to pass everything in and out through component properties.

Until now, canvas components have been properly encapsulated and could not access information and resources from the app.  Everything needed to be passed in to the component through input properties.  We did this to make it easier to share components across apps by using a component library.  Strict encapsulation ensures maximum sharing.

But sometimes you want to define a component just for this app.  You want to reuse a UI widget or create a user defined function as an output property.  No need to worry about sharing.  And to make it easier to write and maintain, let it share in the app’s scope.

We have introduced a new component setting that does exactly this Access app scope:

Note: This setting works properly for new apps but not existing ones.  Existing apps will be supported with a bug fix in Studio version 3.21083.  As a workaround, you can turn off the “Collection access in component scope”  “Retired” feature under “Upcoming features” in the app’s Settings, save the app, and then reopen.

With this setting turned On, your component can now access:

  • Global variables
  • Collections
  • Controls and components on screens, such as a TextInput control
  • Tabular data sources, such as Dataverse tables

When this setting is turned Off, none of these are available to the component.  Set and Collect functions are still available but the resulting variables and collections are scoped to the component instance and not shared with the app.

We had previously allowed app collection access from within a component which was a hole in  encapsulation.  With this new component setting, this exception is no longer needed.  To aid in the migration to the new component setting, we have added a retired app setting to get back to the old behavior.  We will remove this setting in the months ahead based on usage.

Non-tabular data sources, such as Azure Blob Storage or a custom connector, are available whether this new setting is turned on or off.  Think of these more like referencing an environment resource rather than an app resource.  When a component is brought into an app from a component library, these data sources from the environment are also brought in.   In time we plan to do this for tabular data sources too, but there are complications with ensuring there is only one connection to the table so that caches are handled correctly.

Components in a component library can never have access to app scope, as there is no single app scope to refer to, so this setting is not available in this context and effectively off.  Once imported into an app, and if customization has was allowed by the component maker, the switch can be enabled and the component modified to use app scope.

As always, your feedback on the Power Apps community forum is very helpful to us.   We’d love to hear your ideas for how we can make components even more helpful to you.