Hi @Anonymous ,
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