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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Basic question regardi...
Power Apps
Answered

Basic question regarding how to "re-use" a function

(0) ShareShare
ReportReport
Posted on by 10

I have a Basic question regarding how to "re-use" a function

This is super basic, but I am stuck.

I have a screen with a gallery, and a Button, Icon and Text Box.

All three share the same Action  onselect function.

Right now?  I copy paste the function to each Action / Onselect box.

Obviously this is not a best practice.

 

Where should I put the function code and how can I reference it from the three objects?

 

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @eschreibman 

    If this is in the Gallery and they are all the same, you can put the function in the OnSelect of the Gallery and then simply have your inner controls use Select(Parent) on their OnSelect actions.

     

    Is your scenario more complex than that?

     

  • eschreibman Profile Picture
    10 on at

    Yes, my gallery on select is a filter looking at a text box.

     Select(Parent) currently goes to a 'details' page for the item.

     

    The on select function I am not wanting to duplicate is a looong function to export the filtered list to excel by  calling a power automate script.

     

     

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @eschreibman 

    In this case, utilize a Toggle control.

    My guess is that your actions are specific to data from the row of the gallery you are on.  So, let's approach that way.

     

    Place a toggle on the screen (you can set visible to false).

     

    In the OnCheck action of the toggle, place your long formula (after refactoring, perhaps less long) and at the very end of the Formula add the following: UpdateContext({lclDoAction: Blank()})

    Now for the Default property of the toggle, set the formula to !IsBlank(lclDoAction)

    In the gallery, set the OnSelect of the controls you want this on to: UpdateContext({lclDoAction: ThisItem})

     

    Now, back to the OnCheck action - change any references of ThisItem in your formula to lclDoAction (as this will now have "ThisItem" from the gallery).

     

    Keep one thing in mind though...when you use a Toggle like this, it runs in parallel to your app.  So, if you think there is a chance that someone might click one row and then another row before the toggle action is complete, then factor that into your formulas.  Easiest way is to set the display mode properties of your controls in the Gallery to : If(IsBlank(lclDoAction), Edit, Disabled)

     

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard