• About
  • D365 Consulting
  • Technical Services
  • D365 Integration
  • D365 Upgrade
  • Blog
  • Contact
  • About
  • D365 Consulting
  • Technical Services
  • D365 Integration
  • D365 Upgrade
  • Blog
  • Contact
Dynamics 365 F&O
Browse: Home / Blog / Power Apps – Code Reuse
09Dec2020

Power Apps – Code Reuse

by Wolftek in Dynamics 365 F&O, Power Apps

Yes, we know. No self-respecting D365 developer can stand the idea of writing the same line of code twice. Code reusability is at the core of the object-oriented development and certainly is in our book. As it stands, Power Apps aren’t lending easily to code reuse at the moment. Therefore, a creative approach is called for. One way code reuse can be achieved is by implementing the logic on a ‘click’ of a button (OnSelect event) and then ‘clicking’ the button programmatically throughout the application. Note, that this approach is limited to the same-page context; and while it is possible to extend it to other pages in your application, the user experience may be compromised (page flickering etc.).

Here is a flavor of how it is done:

  • Create ‘invisible’ buttons to mimic functions – we like to prefix these with ‘function*’ to indicate their purpose.
  • Implement logic on the OnSelect event
  • In the below example, one ‘function’ calls two other functions. RefreshCollections() invokes the getSales() and the getCustomers() logic:

  • This ‘function’ could then be leveraged from different events on the page. For example, on page load and on a periodic data refresh timer tick:

WolftekPost author

Add some widgets to this area!

  • About
  • D365 Consulting
  • Technical Services
  • D365 Integration
  • D365 Upgrade
  • Blog
  • Contact

© 2022 Wolftek, Inc.