web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Is there really no way...
Power Apps
Unanswered

Is there really no way to reuse code?

(0) ShareShare
ReportReport
Posted on by 77

I have buttons on three different screens on my app that do the same things. Some of these do three or four things when you push them. As far as I can tell, the only way to get them all do the same thing is to cut and paste the code from one to another.

 

Am I missing something?

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    No there is no way to directly reuse code.  Depending on the code you can often put it in one control's onSelect and then simply add Select(control) to another controls onSelect to execute the same code.  But that's only if the code doesn't depend on the context of the OnSelect to run correctly.

  • TheRobRush Profile Picture
    11,128 Moderator on at

    Depending on what they are doing you can make a Custom Component that you use throughout your app. But if it's limitations don't work for your use case then yes, copy paste. Though you can copy paste the control itself, don't necessarily need to place a new one and copy paste the code inside it.

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Pjames43 

    Depends on how you look at things!  If you are looking at PowerApps as development (which it is not), then no, "code" is not reusable in such a way and the only options you have are components or simulating actions with Select functions.

    If you look at how PowerApps was designed - around Excel - then you are creating formulas in "cells" just like Excel, so you can reference anything from anywhere and this provides what would be consider re-usable.  

     

    So in your scenario, a component to serve as the buttons for across all the screens with a behavioral property that will initiate a Toggle (as a Select will not work across multiple screens) on some screen that has the Formula in it that you want to re-use.  This is all quite possible to do.

     

    I hope this is helpful for you.

  • Pjames43 Profile Picture
    77 on at

    Is there actually a way to build a component that references specific items inside your app, like "Navigate(MyHomeScreen)"? I couldn't get that work. The fact that Select() doesn't work across screens seems like a bug honestly. I can get the properties of a button on another screen, but I cannot Select it? Huh?

     

    It just feels like it is certainly marketed by Microsoft as being substantially more capable than Excel. Honestly, I didn't know that it was designed so much around Excel, and that explains a lot. I barely use Excel so maybe that is why I struggle with Power Apps so much.

     

    Or maybe my frustration comes mostly from how Microsoft is marketing Power Apps.

    From https://powerapps.microsoft.com:

    Give everyone the power to build the apps they need with advanced functionality previously only available to professional developers—including pre-built AI components.

     

    Not sure what the advanced functionality is if I can only do what Excel can do, but a little prettier. I find it hard to believe that it would take much to add features like writing a simple function, to it. I am not even talking about a complex function, I just mean like a list of commands, that I want to use more than once.

     

    I am stuck using Power Apps because of my company, but honestly Microsoft's "Low Code" approach is the worst of both worlds. It isn't as easy and drag and drop, and you cannot do any real development. I have the same issues with Power Automate. The fact that I can "Peek Code" but not edit it feels a bit like a middle finger from Microsoft.

     

  • TheRobRush Profile Picture
    11,128 Moderator on at

     

    And as for flow, you can edit flows code, just not in the browser. Export your flow and you can then open and edit it in any notepad or whatever you would normally edit code in, then repack and import it back into PowerAutomate, do it sometimes myself just to get some complicated stuff in that the web browser is making hard for me.

    I have to disagree on some of those points. With PowerApps you can certainly do some very impressive stuff, especially since it runs on mobile devices, where your advanced excel functionality (custom coding in the background etc.) is (at least on apple os dont know about android) not an option. When Randy says it is built modeled after excel he isn't saying PowerApps isn't able to handle advanced functionality.

  • TheRobRush Profile Picture
    11,128 Moderator on at

    You can make a custom component and add a button to it and make the onselect Back() this will bring you to previous screen you came from not sure if your home is previous screen from one you will be on or not

  • TheRobRush Profile Picture
    11,128 Moderator on at

    I think this tutorial by @rorybi might be of interest to you PowerApps Tuesdays Tutorial #43

  • Pjames43 Profile Picture
    77 on at

    @TheRobRush wrote:

    I think this tutorial by @rorybi might be of interest to you PowerApps Tuesdays Tutorial #43


    Thanks I will give that a watch.

  • Pjames43 Profile Picture
    77 on at

    @TheRobRush wrote:

    You can make a custom component and add a button to it and make the onselect Back() this will bring you to previous screen you came from not sure if your home is previous screen from one you will be on or not


    That won't work there are seven screens total in my app. Three different ones have the button in question so Back() doesn't really help.

  • Pjames43 Profile Picture
    77 on at

    @TheRobRush wrote:

    I have to disagree on some of those points. With PowerApps you can certainly do some very impressive stuff, especially since it runs on mobile devices, where your advanced excel functionality (custom coding in the background etc.) is (at least on apple os dont know about android) not an option. When Randy says it is built modeled after excel he isn't saying PowerApps isn't able to handle advanced functionality.


    This is specifically what got me so frustrated. Microsoft literally touts Power Apps as having "Advanced Functionality" not the ability to do everything you can in Excel, but on a mobile device. It is definitely never mentioned that the "Advanced Functionality" is just "Advanced Excel Functionality".  It literally says "advanced functionality previously only available to professional developers" on powerapps.microsoft.com so you can understand why some one who make that conclusion. 

     

    I do appreciate the trick to edit a flow. I am going to try that, but again, it seems like bad design by Microsoft to not just let you edit the code directly. Like why even let me see it in that case?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard