cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Amsha5
Helper II
Helper II

Button goes back to default color after refresh

Button 1 is pressed so it changes the color from blue to yellow and it should stay yellow even if the browser get refreshed. 

But right now if the browser get refreshed the app starts from scratch.!!

 

Any idea's?

2 ACCEPTED SOLUTIONS

Accepted Solutions
RusselThomas
Community Champion
Community Champion

Hi @Amsha5 ,

We are all learning every day 🙂

Just a caution - this might be a bit tedious depending on how many buttons you want to do this for.  If you can't avoid people refreshing the entire browser then keep reading...

 

You can create a list in your site and call it ButtonStatesList or something.  

Add columns to identify the button and its state - you can use the default Title column for the button and add a single-line-of-text column called "State". 

Back in your PowerApp, add a datasource by clicking on the data icon on the left of the screen and Add Data - find Sharepoint and add a Sharepoint data source.  Then on the right find and select your site and select your ButtonStatesList.  

With your list connected to your app, add a button and change it's name to "Button1" - you can do this by selecting the button and then either on the right where you see it's name above the properties you can edit the name, or if you're using the Tree View on the left just double-click the button in the tree view and you can rename it.  You can call it whatever you want, it won't change anything other than your ability to easily identify it while looking at your app - what's important is what the buttons saves to SharePoint in the Title column that will associate it with it's own state.

Set the OnSelect: property of your button to;

 

 

With({buttonRecord: LookUp(ButtonStatesList, Title="Button1")}, 
//gets the existing button record, if it exists and places it into a variable called "buttonrecord" that we can reuse later in our formula

If(IsBlank(buttonRecord.State), 
//checks if there's an existing record by checking if the state is blank - i.e. nothing has been captured yet

  Patch(ButtonStatesList, Defaults(ButtonStatesList), {Title: "Button1", State: "On"}), 
  //if it is blank, then we assume there's no record yet and create one the first time the button is pressed, and set it's state to "On"

  Patch(ButtonStatesList, buttonRecord, {Title: "Button1", State: If(buttonRecord.State="Off", "On", "Off")}) 
//if it's not blank, then the record already exists so we update the existing record, setting it to "On" if it's currently "Off" and "Off" if it's currently "On"

)

)

 

 

 Now go to your button Fill: property and set it as follows;

 

 

If(LookUp(ButtonStatesList, Title="Button1", State)="On", Yellow, Blue)

 

 

That should do it.  If you add more buttons, just make sure each button is set to check for whatever Title it's capturing when pressed - Just replace the above with "Button2", "Button3" etc. as you go.  Whenever your app is loaded, the button will get it's Fill color from the list.

You should note this will work fine for one person using the app - PowerApps will refresh the state automatically whenever it's updated by that user for that PowerApps session - but nobody else will see the update unless their app is continuously checking for it, or they update the color themselves and force a refresh for their session.  If you want everyone to see state updates whenever someone else updates them, you'll have to add a timer to Refresh() the data source periodically.  To do this, just add a time control and set the following properties;

  • Duration: 15000 (refreshes every 15 seconds)
  • Repeat: On/true
  • AutoStart: On/true
  • OnTimerEnd: Refresh(ButtonStatesList)
  • Visible: false
  • AutoPause: On/true if your buttons only exist on one screen, Off/false if they are spread across multiple screens

You Hope this helps 🙂

RT

View solution in original post

RusselThomas
Community Champion
Community Champion

Hi @Amsha5 ,

I have some questions - because I don't see how your formula is figuring out which button information it's fetching - and based on your example you need to track the status for three buttons independently.  Is this still what you're trying to do, or did I miss something?

If this is what you're trying to do, then you need to save each button's data and be able to retrieve it, so your buttonState list should have;

  • Three rows with two or three columns - one column for each button that identifies each button uniquely, (initially we were using the Title column) plus at least one column to track clickCount, or two if you're still tracking the button clicked status
Title (Text)clickCount (Number)
Button1 
Button2 
Button3 

Each button should patch it's own Title for future lookups, incrementing it's clickCount.

What I'm seeing in your code is different behaviour;

  • Your lookup is fetching a row from a list called SafetyCross, where the Title is = gblClickCount.  
  • Your Patch statement is likewise patching gblClickCount into the title. 

How is this different for each button?

How are you identifying individual buttons in your Patch or LookUp statements?  

What does this list currently look like?

 

Also, with your Patch, you're saving two identical values - buttonClicks and clickCount.  Are these not the same thing?

 

Admittedly, there are always many ways to achieve the same thing, and you should do what makes you comfortable - but also what makes sense to you.  I built an example using a collection instead of SharePoint, but this should show what I see as your ask - if it's different to this then I'm on the wrong track.

If it's accurate, feel free to download the msapp file attached to see how it was done - you can open it using "Open", "Browse Files" from the maker portal and select the file you downloaded.  Here's what it looks like;

 

buttonClick.gif

 

 

Kind regards,

RT

View solution in original post

17 REPLIES 17
RusselThomas
Community Champion
Community Champion

Hi @Amsha5 ,

The entire app will restart if the browser is refreshed, and all components will be reset to their default state, so this is unavoidable unless you save the state of the button outside the app - for example in a sharepoint list somewhere - and then load the state when the app starts.

Kind regards,

RT

Hello @RusselThomas 

Thanks for the respons dear.

let me just say that i am very new to powerapps. 

I have a sharepoint list and its connected to the app, i just dont know how to record the button status to a column. 

RusselThomas
Community Champion
Community Champion

Hi @Amsha5 ,

We are all learning every day 🙂

Just a caution - this might be a bit tedious depending on how many buttons you want to do this for.  If you can't avoid people refreshing the entire browser then keep reading...

 

You can create a list in your site and call it ButtonStatesList or something.  

Add columns to identify the button and its state - you can use the default Title column for the button and add a single-line-of-text column called "State". 

Back in your PowerApp, add a datasource by clicking on the data icon on the left of the screen and Add Data - find Sharepoint and add a Sharepoint data source.  Then on the right find and select your site and select your ButtonStatesList.  

With your list connected to your app, add a button and change it's name to "Button1" - you can do this by selecting the button and then either on the right where you see it's name above the properties you can edit the name, or if you're using the Tree View on the left just double-click the button in the tree view and you can rename it.  You can call it whatever you want, it won't change anything other than your ability to easily identify it while looking at your app - what's important is what the buttons saves to SharePoint in the Title column that will associate it with it's own state.

Set the OnSelect: property of your button to;

 

 

With({buttonRecord: LookUp(ButtonStatesList, Title="Button1")}, 
//gets the existing button record, if it exists and places it into a variable called "buttonrecord" that we can reuse later in our formula

If(IsBlank(buttonRecord.State), 
//checks if there's an existing record by checking if the state is blank - i.e. nothing has been captured yet

  Patch(ButtonStatesList, Defaults(ButtonStatesList), {Title: "Button1", State: "On"}), 
  //if it is blank, then we assume there's no record yet and create one the first time the button is pressed, and set it's state to "On"

  Patch(ButtonStatesList, buttonRecord, {Title: "Button1", State: If(buttonRecord.State="Off", "On", "Off")}) 
//if it's not blank, then the record already exists so we update the existing record, setting it to "On" if it's currently "Off" and "Off" if it's currently "On"

)

)

 

 

 Now go to your button Fill: property and set it as follows;

 

 

If(LookUp(ButtonStatesList, Title="Button1", State)="On", Yellow, Blue)

 

 

That should do it.  If you add more buttons, just make sure each button is set to check for whatever Title it's capturing when pressed - Just replace the above with "Button2", "Button3" etc. as you go.  Whenever your app is loaded, the button will get it's Fill color from the list.

You should note this will work fine for one person using the app - PowerApps will refresh the state automatically whenever it's updated by that user for that PowerApps session - but nobody else will see the update unless their app is continuously checking for it, or they update the color themselves and force a refresh for their session.  If you want everyone to see state updates whenever someone else updates them, you'll have to add a timer to Refresh() the data source periodically.  To do this, just add a time control and set the following properties;

  • Duration: 15000 (refreshes every 15 seconds)
  • Repeat: On/true
  • AutoStart: On/true
  • OnTimerEnd: Refresh(ButtonStatesList)
  • Visible: false
  • AutoPause: On/true if your buttons only exist on one screen, Off/false if they are spread across multiple screens

You Hope this helps 🙂

RT

Amsha5
Helper II
Helper II

@RusselThomas 

 

You did it, thank you dear 👍

Amsha5
Helper II
Helper II

 

Hello @RusselThomas 

Could you help me again please? 

I have these 3 buttons that changes 7 different colors one color pr. click. i want to patch button values to my sharepoint list so when i restart the app the buttons stays at same color and dont go back to default. Just the same like the first problem but now the buttons changes between 7 colors. 

 

 

 

 

 

 

The code is for each button: 

On.Select

If(gblClickCount<7;Set(gblClickCount;gblClickCount+1);Set(gblClickCount;1));;

 

 

 Fill.
Switch(gblClickCount;
 
1; Green;
 
2; Yellow;
 
3; SkyBlue; 
 
4; Orange;
 
5; MediumPurple;
 
6; Red;
 
Capture1.PNG
RusselThomas
Community Champion
Community Champion

Hi @Amsha5 ,

So at this point, the user experience becomes a critical deciding factor in how you take it forward.

Do you want each user to keep track of their own button clicks, or are the button states universal (the same) for all users?  i.e. if I click button 3 through to Orange and you're running the app, do you want to see button 3 change to Orange?  Or do you want to track your own button clicks independent from mine?

Kind regards,

RT

@RusselThomas 

Thank you for your respons.

All users should be the same there is only one display for this app. I just dont want to lose any data when the app gets refreshed in the web browser . 

 

Best regards 

 

 

RusselThomas
Community Champion
Community Champion

Hi @Amsha5 ,

That makes it easier, as you're already saving a row of data for each button 'state'.

All you need to do is add a number column to your button state list - call it 'buttonClicks' or something that makes sense to you - this is where you can store the number of clicks the button is on.  Remember to refresh the data source in PowerApps after you've added the column to SharePoint ("Data" menu, "..." next to your data source, "Refresh")

If we take a step back and look at the solution, it may make more sense to keep your number/colour reference as a lookup table than just existing in logic.  By this I mean, instead of switching the value of ClickCount for each button to get the fill colour, it would be better to store the clickcount/fillcolour in a table and just look it up.

This way, if you want to change the colour of a number, you don't have to go and edit three buttons worth of code to do it.

There is a behaviour called App Start you can use to initialise information for your app.  This will run exactly once, when your app starts.  You can put any behaviour functions in app start, including collecting data from a source, setting variables, or in this case, creating a reference table for your app to use.

On your left navigation menu, above your first screen (usually Screen1), you should see "App". Click on this, and then make sure your formula bar property is set to OnStart (the down arrow to the left of the fx on the formula bar).

This can go in your OnStart: property;

 

ClearCollect(collectClickColours; {
  numClicks: 1; fillColour: Green;
  numClicks: 2; fillColour: Yellow;
  numClicks: 3; fillColour: SkyBlue;
  .....
  });;

 

So here we'll set up our collection called collectClickColours with a column "numClicks" and corresponding "fillColour" (you can call the columns what you like, as long as it makes sense to you - just replace the ..... with the rest of the numbers and colours - I'm lazy 🙂)

Our buttons will reference this table to get their colours - and if we want to change a numbers colour, we only have to do it here, once.

 

Now your buttons' Fill: properties can look as follows;

 

LookUp(collectClickColours;
     numClicks = LookUp('buttonStatesList'; Title='Button1'; clickCount); fillColour
)

 

 If there's only one screen/user, you don't have to worry about refreshing - and if the app 'reboots', then it should fetch the last saved click counts.

[Edit]

I forgot to add, you'll want to include the clickcount incrementer in your button OnSelect: patch update.  Editing the code from the original post, it would look something like this;

With({buttonRecord: LookUp(ButtonStatesList, Title="Button1")}, 

If(IsBlank(buttonRecord.State), 

  Patch(ButtonStatesList, Defaults(ButtonStatesList), {Title: "Button1", State: "On", buttonClicks: 1}), 
  
  Patch(ButtonStatesList, buttonRecord, {Title: "Button1", State: If(buttonRecord.State="Off", "On", "Off"), buttonClicks: buttonRecord.buttonClicks+ 1})
)

)

Try it out and let me know how it goes 🙂

Kind regards,

RT

Hello @RusselThomas

Its recording to the sharepoint list but i getting error when i am adding the code OnStart: 2.PNG 

 

Helpful resources

Announcements

Check Out the February 2024 Dynamics 365 Newsletter

Some of our most active Power Platform Community members are also active in our D365 Community. This month, we are excited to share the latest news from the D365 Community with you.   Our Dynamics365 Community has updated yet again! Since launching in June of 2023, the new Community has seen consistent updates and exciting new ways to feature and celebrate its members. In the latest edition of the Dynamics365 Community newsletter, you can see the new Leaderboard feature! This feature showcases which Community members have earned the most points over the previous month, enabling them to see how they are doing with their engagement--and their progress toward Super User status. Visit the leaderboard for yourself: https://aka.ms/d365clb     Read the whole newsletter featuring the new leaderboard as well as the D365 Monthly Community Member spotlight, FastTrack Tech Talks, upcoming events, and more. February 2024 Dynamics 365 Community Newsletter

Celebrating a New Season of Super Users with Charles Lamanna, CVP Microsoft Business Applications

February 8 was the kickoff to the 2024 Season One Super User program for Power Platform Communities, and we are thrilled to welcome back so many returning Super Users--as well as so many brand new Super Users who started their journey last fall. Our Community Super Users are the true heroes, answering questions, providing solutions, filtering spam, and so much more. The impact they make on the Communities each day is significant, and we wanted to do something special to welcome them at our first kickoff meeting of the year.   Charles Lamanna, Microsoft CVP of Business Applications, has stressed frequently how valuable our Community is to the growth and potential of Power Platform, and we are honored to share this message from him to our 2024 Season One Super Users--as well as anyone who might be interested in joining this elite group of Community members.     If you want to know more about Super Users, check out these posts for more information today:    Power Apps: What is A Super User? - Power Platform CommunityPower Automate: What is A Super User? - Power Platform Community Copilot Studio: What is A Super User? - Power Platform Community Power Pages: What is A Super User? - Power Platform Community

February 2024 User Group Update: Welcoming New Groups and Highlighting Upcoming Events

It's a new month and a brand-new year, which means another opportunity to celebrate our amazing User Groups!Each month, we highlight the new User Groups that have joined the community. It's been a busy season for new groups, because we are thrilled to welcome 15 New User Groups! Take a look at the list below, shared by the different community categories. If your group is listed here, give this post a kudo so we can celebrate with you!   We love our User Groups and the difference they make in the lives of our Community! Thank you to all the new User Groups, new User Group leaders--we look forward to hearing about your successes and the impact you will leave!   In addition to our monthly New User Group spotlight, it's a great time to share some of the latest events happening in our User Group community! Take a look at the list below to find one that fits your schedule and need! There's a great combination of in-person and virtual events to choose from. It's a great time of year to connect and engage with User Groups both locally and online. Please Welcome Our NEW User Groups   Power Platform: Heathcare Power Platform User Group Power Platform Connect Hub Power Platform Usergroup Denmark Mexico Norte- Power Platform User Group Pune Power User Group Sudbury Power Platform User GroupMicrosoft User Group GhanaMPPBLR - Microsoft Power Platform Bengaluru User Group Power Apps:   Myrtle Beach Power Platform User GroupAnanseTechWB PowerApps Copilot Studio: Pathfinders Power Platform Community Dynamics365: Cairo, Egypt MSD 365 Business Central/NAV/F&O User GruopMS Dynamics 365 Business Central LatamCincinnati OH D365 F&O User Group February User Group Events February 2024 Cleveland Power Platform User GroupPortallunsj - Februar 2024Indiana D365/AX February User Group MeetingQ1 2024 KC Power Platform and Dynamics 365 CRM Users Group 

Super Users 2024 Season One is Here!

   We are excited to announce the first season of our 2024 Super Users is here! Our kickoff to the new year welcomes many returning Super Users and several new faces, and it's always exciting to see the impact these incredible individuals will have on the Community in 2024! We are so grateful for the daily difference they make in the Community already and know they will keep staying engaged and excited for all that will happen this year.   How to Spot a Super User in the Community:Have you ever written a post or asked for help in the Community and had it answered by a user with the Super User icon next to their name? It means you have found the actual, real-life superheroes of the Power Platform Community! Super Users are our heroes because of the way they consistently make a difference in the Community. Our amazing Super Users help keep the Community a safe place by flagging spam and letting the Community Managers know about issues. They also make the Community a great place to find answers, because they are often the first to offer solutions and get clarity on questions. Finally, Super Users share valuable insights on ways to keep the Community growing, engaging, and looking ahead!We are honored to reveal the new badges for this season of Super Users! Congratulations to all the new and returning Super Users!     To better answer the question "What is a Super User?" please check out this article: Power Apps: What is A Super User? - Power Platform CommunityPower Automate: What is A Super User? - Power Platform Community Copilot Studio: What is A Super User? - Power Platform Community Power Pages: What is A Super User? - Power Platform Community

January 2024 Community Newsletter

Welcome to our January Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members. If you're new to the Community, please make sure to follow the latest News & Announcements in each Community and check out the Community on LinkedIn as well! It's the best way to stay up-to-date in 2024 with all the news from across Microsoft Power Platform and beyond.      COMMUNITY HIGHLIGHTS Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, giving (and receiving!) kudos, and consistently providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, make it your New Year's Resolution to be more active in the community in 2024.   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzWarrenBelzPstork1saudali_25LaurensMPstork1stephenrobertLucas001AARON_ClbendincpaytonSurendran_RANBNived_NambiarMariamPaulachanNikhil2JmanriqueriosANBJupyter123rodger-stmmbr1606Agniusstevesmith27mandelaPhineastrice602AnnaMoyalanOOlashynBCLS776grantjenkinsExpiscornovusJcookSpongYeAARON_CManishSolankiapangelesPstork1ManishSolankiSanju1Fubar   LATEST NEWS Power Platform 2024 Release Wave Highlights This month saw the 2024 Release Wave 1 plans for Microsoft Power Platform and Microsoft Dynamics 365- a compilation of new capabilities planned for release between April and September 2024. Click here to read Corporate Vice President Maureen (Mo) Osborne's detailed breakdown of the upcoming capabilities, and click the image below to check out some of the Power Platform 2024 Release Wave 1 highlights.     "What's New" Power Platform Shorts Series This month we also launched our brand-new 'Power Shorts' series on YouTube - a selection of super sweet snapshots to keep you in the loop with all the latest trends from across the Power Platform and beyond. Click the image below to check out the entire playlist so far, and don't forget to subscribe to our YouTube channel for all the latest updates.   Super User In Training (S.U.I.T) It was great to see the Power Platform Community officially kick off Season One of their Super User in Training (SUIT) program this month! Their first meeting saw an amazing turnout of over 300 enthusiastic participants who started their dynamic journey toward becoming Super Users. Huge thanks to Manas Maheshwari, Eric Archer, Heather Hernandez, and Duane Montague for a fantastic kick-off. The first meeting also saw seasoned Super User, Drew Poggemann, share invaluable insights on navigating the #MicrosoftCommunity with finesse. Many thanks to Drew for setting the stage and emphasizing the importance of active engagement and the art of providing thoughtful community solutions. If you want to learn more about the features and benefits of gaining Super User status, click the image below to find out more, and watch this space for more info about Season Two and how you can SUIT UP in the community!     UPCOMING EVENTS Microsoft 365 Community Day - Miami - February 1-2, 2024 It's not long now until the Microsoft 365 Community Day Miami, which will be taking place at the Wolfson Campus at Miami Dade College on 1-2 Feb. 2024. This free event is all about unlocking the full potential of Power Platform, Microsoft 365, and AI, so whether you’re a tech enthusiast, a business owner, or just curious about the latest Microsoft advancements, #M365Miami is for you.   The event is completely free and there will sessions in both English and Spanish to celebrate the vibrant and diverse make-up of our amazing community. Click the image below to join this amazing Community Day in Miami and become a part of our incredible network of learners and innovators!     Microsoft Fabric - Las Vegas - March 26-28, 2024 Exciting times ahead for the inaugural #MicrosoftFabric Community Conference on March 26-28 at the MGM Grand in Las Vegas. And if you book now, you can save $100 off registration! The Microsoft Fabric Conference will cover all the latest in analytics, AI, databases, and governance across 150+ sessions.   There will be a special Community Lounge onsite, interactive learning labs, plus you'll be able to 'Ask the Experts' all your questions to get help from data, analytics, and AI specialists, including community members and the Fabric Customer Advisory Team. Just add the code MSCUST when registering for a $100 discount today. Click the image below to find out more about the ultimate learning event for Microsoft Fabric!     Microsoft 365 Conference - Orlando - April 30 - May 2, 2024 Have you added The Microsoft 365 Conference to your community calendar yet? It happens this April 30th - May 2nd in Orlando, Florida. The 2024 Microsoft 365 Conference is one of the world’s largest gatherings of Microsoft engineers and community, with a strong focus on Power Platform, SharePoint, Azure, and the transition to an AI-powered modern workplace.   Click the image link below to find out more and be prepared to be enlightened, educated, and inspired at #M365Conf24!   LATEST COMMUNITY BLOG ARTICLES Power Apps Community Blog Power Automate Community Blog Copilot Studio Community Blog Power Pages Community Blog Check out 'Using the Community' for more helpful tips and information: Power Apps, Power Automate, Copilot Studio, Power Pages  

Did You Attend the Microsoft Power Platform Conference in 2022 or 2023? Claim Your Badge Today!

If you were one of the thousands of people who joined us at the first #MPPC Microsoft Power Platform Conference in 2022 in Orlando--or attended the second-annual conference in Las Vegas in 2023--we are excited to honor you with a special community badge! Show your support for #MPPC Microsoft Power Platform Conference this year by claiming your badge!         Just follow this link to claim your badge for attending #MPPC in 2022 and/or 2023: MPPCBadgeRequest    Want to earn your badge for 2024? Just keep watching our News & Announcements for the latest updates on #MPPC24.

Top Solution Authors
Top Kudoed Authors
Users online (2,606)