cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Invoking App Run on Start on demand

I want to be able to call Run on Start for the app by the OnVisible action of a Screen.  Basically, I have a collection that is utilized on multiple screens and needs to be refreshed based on actions on each of those screens.  Ideally, I would like to have the code for that collection reside in a single place and be able to run that from multiple screens so I don't have to copy and past that collection code in each screen and at each point on each screen where it needs to be refreshed.  Is this possible or does anyone have a suggestion for how to accomplish this?

 

Thanks.  

1 ACCEPTED SOLUTION

Accepted Solutions

@rpitts 

Another method you can do to put your Formulas in one place is what I call a dynamic variable.

 

You would need to get rid of the collection (as you most likely don't need it anyway) and simply utilize this global "variable".

 

Here's how it works...

There are really only two controls in the PowerApps arsenal of controls that will give you IT's items.  Those are the Gallery (the AllItems property - which is a bit of extra overhead you don't need) and a DataCard.

When I mention DataCard everyone thinks - Forms.  But this is not the case, there is one other control that contains a datacard, and that is a Canvas control - this is perfect for this (and in fact, from our app design perspective we probably use Collections less than 1% of the time and these DataCards over 99% of the time - They work great and completely change how you design your apps, not to mention speed them up!).  

 

Now, you cannot add a Canvas or DataCard directly from the insert menu.  So what to do?  You need to add a new screen to your App, and it needs to be a Scrollable screen.  The scrollable screen will add a canvas and a datacard in it.  You can cut and paste the entire Canvas control from that screen to another of your choice - OR leave it where it is - it is Global.  You are not going to make it visible or do anything else with it in terms of controls, so where it is and what size it is will not be important.

 

NOW...the fun!!

There is an Update property in the Datacard.  This is just like the one on a regular form datacard, but without all the form connections.  You can put anything you want in there as long as it is a record.

We will use this property.

 

Let's set the stage - you have a Gallery on your screen and another on another screen as well as a Chart and a Combobox - all using the exact same data (i.e. formula). AND, let's say there is a Dropdown that depending on what is selected, will determine the data for all of those items properties.

This is annoying for many reasons:  1) if it is collection based, then you have to constantly, and in every place, need to recollect the data.  2) You have now duplicated formulas - if you need to change something, you have to do it in every place 3) it becomes a challenge to figure out what is where and where you might have forgotten to change something.

 

Now, back to our Update property.  In there we put a formula such as :

{
    MyItems:
        Filter(someData, someColumn=Dropdown1.Selected.Value)
}

Your Update property is now giving us a record that has a table in it that is based on the Filter which is based on the Dropdown.

For our Galleries, we will simply replace the Items properties with : theDataCardName.Update.MyItems

Same for the combobox and the chart, etc.

 

Taking it a step further, we can add to this record even more things.  So, let's say that our Galleries need slightly different data and our chart as well.  First gallery wants just the Items, the second will have a calculated Sum of all the items, the Chart will want its data as Labels and Series, and our Combobox will have all the Items, PLUS we want to have an "All" as the first item in the list. We can do ALL of that in one place AND it will be dynamic based on the Dropdown (in this case).

 

So...Something like this:

With(_items: Filter(someData, someColumn=Dropdown1.Selected.Value)},

  {
    MyItems: _items,
    Gallery2Items : AddColumns(_items, "someSum", Sum(_items, SomeValueColumn),
    ChartItems: AddColumns(GroupBy(_items, "someLabelColumn", "_recs"), "seriesValue", Sum(_recs, someValue))
    ComboboxItems: ForAll(Sequence(CountRows(_items)+1, 0), {Item: If(Value=0, "All", Last(FirstN(_items, Value)).someColumnforCombobox)})

  }

)

 

In the above we just got all of the items tables for 4 controls ALL in one place and all based on the Dropdown in our app.

No collections needed and we don't have to do anything to instantiate this formula to evaluate and have the correct values (no Onxxx actions, no behavioral actions, etc.)  It all just changes dynamically based on our Dropdown.

 

Again, this method works great and the sky is the limit on what you put in to these.  Best part is that your formulas are all in one place and you completely cut out SO many extra formulas that you would normally need to make the above happen in other ways.

 

I do have a video and post coming out on this topic, but I am backlogged on these at the moment...so, the above is kind of a sneak-peek at what that will be like.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi,

I am pretty confident when I say that the on start of an app code, is limited to just executing on the start of an app or manually running it when editing an app.

In terms of something you could do to facilitate your need. Now this doesn't address the one place but I do find it helps when you need to contain a bit of logic that could be easily executed in multiple actions on one screen.

 

That is to get the code in the On Select property of a button. Hide the button and just select the button whenever you want to execute that bit of code.

 

Thanks

 

Henry

@rpitts 

Another method you can do to put your Formulas in one place is what I call a dynamic variable.

 

You would need to get rid of the collection (as you most likely don't need it anyway) and simply utilize this global "variable".

 

Here's how it works...

There are really only two controls in the PowerApps arsenal of controls that will give you IT's items.  Those are the Gallery (the AllItems property - which is a bit of extra overhead you don't need) and a DataCard.

When I mention DataCard everyone thinks - Forms.  But this is not the case, there is one other control that contains a datacard, and that is a Canvas control - this is perfect for this (and in fact, from our app design perspective we probably use Collections less than 1% of the time and these DataCards over 99% of the time - They work great and completely change how you design your apps, not to mention speed them up!).  

 

Now, you cannot add a Canvas or DataCard directly from the insert menu.  So what to do?  You need to add a new screen to your App, and it needs to be a Scrollable screen.  The scrollable screen will add a canvas and a datacard in it.  You can cut and paste the entire Canvas control from that screen to another of your choice - OR leave it where it is - it is Global.  You are not going to make it visible or do anything else with it in terms of controls, so where it is and what size it is will not be important.

 

NOW...the fun!!

There is an Update property in the Datacard.  This is just like the one on a regular form datacard, but without all the form connections.  You can put anything you want in there as long as it is a record.

We will use this property.

 

Let's set the stage - you have a Gallery on your screen and another on another screen as well as a Chart and a Combobox - all using the exact same data (i.e. formula). AND, let's say there is a Dropdown that depending on what is selected, will determine the data for all of those items properties.

This is annoying for many reasons:  1) if it is collection based, then you have to constantly, and in every place, need to recollect the data.  2) You have now duplicated formulas - if you need to change something, you have to do it in every place 3) it becomes a challenge to figure out what is where and where you might have forgotten to change something.

 

Now, back to our Update property.  In there we put a formula such as :

{
    MyItems:
        Filter(someData, someColumn=Dropdown1.Selected.Value)
}

Your Update property is now giving us a record that has a table in it that is based on the Filter which is based on the Dropdown.

For our Galleries, we will simply replace the Items properties with : theDataCardName.Update.MyItems

Same for the combobox and the chart, etc.

 

Taking it a step further, we can add to this record even more things.  So, let's say that our Galleries need slightly different data and our chart as well.  First gallery wants just the Items, the second will have a calculated Sum of all the items, the Chart will want its data as Labels and Series, and our Combobox will have all the Items, PLUS we want to have an "All" as the first item in the list. We can do ALL of that in one place AND it will be dynamic based on the Dropdown (in this case).

 

So...Something like this:

With(_items: Filter(someData, someColumn=Dropdown1.Selected.Value)},

  {
    MyItems: _items,
    Gallery2Items : AddColumns(_items, "someSum", Sum(_items, SomeValueColumn),
    ChartItems: AddColumns(GroupBy(_items, "someLabelColumn", "_recs"), "seriesValue", Sum(_recs, someValue))
    ComboboxItems: ForAll(Sequence(CountRows(_items)+1, 0), {Item: If(Value=0, "All", Last(FirstN(_items, Value)).someColumnforCombobox)})

  }

)

 

In the above we just got all of the items tables for 4 controls ALL in one place and all based on the Dropdown in our app.

No collections needed and we don't have to do anything to instantiate this formula to evaluate and have the correct values (no Onxxx actions, no behavioral actions, etc.)  It all just changes dynamically based on our Dropdown.

 

Again, this method works great and the sky is the limit on what you put in to these.  Best part is that your formulas are all in one place and you completely cut out SO many extra formulas that you would normally need to make the above happen in other ways.

 

I do have a video and post coming out on this topic, but I am backlogged on these at the moment...so, the above is kind of a sneak-peek at what that will be like.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Randy, thank you!  You have seriously blown my mind.  Just beginning to play with this but I think this is going to simplify so any things.  And now I have my work cut out for me redesigning my apps.  🙂  Thanks again.

 

- Randy Pitts

@rpitts 

It makes all the difference in the world with PowerApps design!!  

I will have a video out on this soon.  If you're interested, subscribe to my channel with alerts (video link below in my signature line) and you'll get a notice when it is published.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you for the Datacard tip @RandyHayes. I had up until now been using multiple galleries for this but having multiple items in a single Datacard's record is much nicer!

Anonymous
Not applicable

Hi @RandyHayes ,

Really interesting comment and I implemented it immediately. However, it can have a maximum number of 2000 records, is that correct? 

 

How would go around this? For example if I have a debtor lists which consists of more than 2000 records in a sharepoint lists. How would you make sure all those are loaded in the update field of the datacard and therefore can use more than 2000 debtors in other places of my app?

 

Looking forward to your response!

 

 

Hello @rpitts, Just wanted to check if you have made that video. Please post the link here.

Hi Randy,

I'm very interested in this topic, did you ever make a video about this?  If so please post a link.  I've checked your YT channel and don't find it there.  

Thanks for your write up.  So intriguing don't have my head around it yet.

It seems you're missing an opening curly brace. I think it's supposed to be:

 

 

With({_items:

 

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (903)