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 / Updatecontext group bu...
Power Apps
Answered

Updatecontext group button colors and patching/collecting fields

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello and Good Afternoon,

 

Im stuck on a problem. A client has requested rather than use dropdowns etc to use buttons (lots of buttons..) and im a little stuck on how to do whats required, however im very confident it can be done.

 

Heres a pic of the test app

 

forz.png

 

My first question is how do i only allow one button in the group to be selected and what ever button is selected goes green and that value is kept?

 

My code below works to change it however i want the user to be able to deselect it and change the color back and for the user to select another button in the group and the first button is deselected.

 

The onselect code is

UpdateContext({pressedButton:!true});UpdateContext({pressedButton:true})

and the fill code is

 

If(pressedButton=true, Color.Green, Color.Blue)

i would then like the button that is selected to have a value in a choice or number or text field to be saved to sharepoint once i press the patch and collect syntax 

 

ie 

 

If(Connection.Connected
	,Patch('TESTLIST',
		Defaults('TESTLIST'),
		{
 CHOICE COLUMN: BUTTON1VALUE (or button2 etc if selected).Selected,
 TEXT COLUMN : BUTTON1VALUE (or button2 etc if selected).Text,
 NUMBER Value( BUTTON1VALUE (or button2 etc if selected).Text)	
		}
	)
	,Collect(TESTCOLLECTION,
		{
		 CHOICE COLUMN: BUTTON1VALUE (or button2 etc if selected).Selected,
 TEXT COLUMN : BUTTON1VALUE (or button2 etc if selected).Text,
 NUMBER Value( BUTTON1VALUE (or button2 etc if selected).Text)	
		}
	)
);
Navigate(Screen2, ScreenTransition.None)

If i cant do choice columns etc no real problem as i have control over this database,

 

Anyhelp would be very much appreciated,

 

Thankyou

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Since you will most likely have a variable number of "buttons" needed and will endlessly be adding buttons for choices (if they change), you might want to consider a different tactic.

    The use of a Gallery is a real hero in this case.

    Rather than explain a lot here, I've attached a sample App that will give you what you are looking for with 2 controls - a button in a Gallery

    If you look at the App OnStart, you will see that to start out we load up a little collection of the items that will be values for the buttons.  To adapt this App to a choice column, connect to your datasource and then change the OnStart to the following:

    ClearCollect(buttonList,
     AddColumns(
     RenameColumns(
     Choices(yourDataSource.yourChoiceColumn),
     "Value", "button") , 
     "selected", false)
    )
    

    This will do as you are looking to do.

     

    However...you mention "Groups" but don't really explain that concept in your question.  So, I'm not really sure how that fits in.

     

    As for your Patch statement.  All is good there except the Number value.  If you are getting the information from a Choice column, then you will really only have values.  If you have another source for the number values (such as a lookup), then this is easily added in.

     

    I hope this is somewhat clear and helpful for you.

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Based on the needs that you mentioned, I think it is not necessary to add multiple buttons individually within your app. As an alternative (easy way) solution, I think the Gallery could achieve your needs.

     

    I have made a test on my side, please take a try with the following workaround:7.JPG

     

    8.JPG

     

    9.JPG

     

    10.JPG

    Set the OnStart property of the App control to folowing formula:

    ClearCollect(
     ButtonCollection,
     {ButtonText: "Button", IsClicked: false},
     {ButtonText: "Button2", IsClicked: false},
     {ButtonText: "Button3", IsClicked: false},
     {ButtonText: "GROUPButton", IsClicked: false},
     {ButtonText: "GROUPButton2", IsClicked: false},
     {ButtonText: "GROUPButton3", IsClicked: false}
    );
    Set(CurrentButtonText, Blank());

    Add a Gallery control (Gallery1) within your app, set the Items property to following:

    ButtonCollection

    Set the WrapCount property of the Gallery to following:

    3 /* <-- Display three buttons one row */

     

    Add a Button control within above Gallery, set the Text property to following:

    ThisItem.ButtonText

    Set the Fill property of the Button control to following:

    If(ThisItem.IsClicked, RGBA( 0, 128, 0, 1 ),RGBA(56, 96, 178, 1))

    Set the OnSelect proeprty of the Button control to following:

    If(
     CurrentButtonText = ThisItem.ButtonText || CurrentButtonText = Blank(),
     Set(CurrentButtonText, ThisItem.ButtonText);Patch(ButtonCollection, ThisItem, {IsClicked: !ThisItem.IsClicked}),
     Set(CurrentButtonText, ThisItem.ButtonText);UpdateIf(ButtonCollection, true, {IsClicked:false});Patch(ButtonCollection, ThisItem, {IsClicked: !ThisItem.IsClicked})
    )

    Please check the following GIF screenshot for more details:Test.gif

     

    In addition, if you want to save the selected Button text value into your SP List, please consider modify your formula as below:

    If(
    Connection.Connected,
    Patch(
    'TESTLIST', Defaults('TESTLIST'), { CHOICECOLUMN: {
    Value: Gallery1.Selected.ButtonText /* <-- Gallery1 represents the Gallery control in above solution */
    }, TEXTCOLUMN : Gallery1.Selected.ButtonText, NUMBERColumn: Value(Gallery1.Selected.ButtonText) } ),
    Collect(
    TESTCOLLECTION, { CHOICECOLUMN: {
    Value: Gallery1.Selected.ButtonText
    }, TEXTCOLUMN : Gallery1.Selected.ButtonText, NUMBERColumn: Value(Gallery1.Selected.ButtonText) } ) ); Navigate(Screen2, ScreenTransition.None)

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

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

    @v-xida-msft thanks for re-explaining the solution that I provided with my example app.

     

    @Anonymous 

    The error in the alternate duplicate solution provided will still be with the value 

    NUMBERColumn: Value(Gallery1.Selected.ButtonText)	
    

    Also, this will yield improper results as the formula suggested by @v-xida-msft references Gallery1.Selected.  The premise of what you are doing is to have only a single item "selected".  If a user clicks on another button without "clearing" the first one, then the formula provided will have incorrect results as the Selected item has now changed.

     

    Instead you will want to replace the Gallery1.Selected with Lookup(Gallery1.AllItems, selected).button (working with the names from my sample app where we used selected and button)

     

    Also, as I mentioned in the original solution response...

    As for your Patch statement. All is good there except the Number value. If you are getting the information from a Choice column, then you will really only have values. If you have another source for the number values (such as a lookup), then this is easily added in.

    The above formula will have a result of 0 since your button text is a string that is non-numeric. If you need values for your buttons (numeric), then I would suggest putting them into your Items definition for the Gallery

     

    Also - Wasn't entirely clear from your original question if you wanted the users to be forced to "Unselect" a button before choosing another, or if they could choose any button regardless. 

     

    I've provided another sample app that properly demonstrates the use of the numeric value in your choices.  Also, I've accounted for the ability for a user to select any button they want, or to be forced to unselect the current button in order to choose another. (In PowerApps, Create and App or Open an existing App, then File->Open->Browse for downloaded file).

     

    Key areas to look at in the app:

       App - OnStart

       Gallery1 - Items, OnSelect

       Button1 - Fill, HoverFill

       HtmlText1 - HtmlText

     

    I hope this is clearer for you and helpful.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @RandyHayes wrote:

    @v-xida-msftthanks for re-explaining the solution that I provided with my example app.

     

    @Anonymous 

    The error in the alternate duplicate solution provided will still be with the value 

    NUMBERColumn: Value(Gallery1.Selected.ButtonText)	

    Also, this will yield improper results as the formula suggested by @v-xida-msft references Gallery1.Selected.  The premise of what you are doing is to have only a single item "selected".  If a user clicks on another button without "clearing" the first one, then the formula provided will have incorrect results as the Selected item has now changed.

     

    Instead you will want to replace the Gallery1.Selected with Lookup(Gallery1.AllItems, selected).button (working with the names from my sample app where we used selected and button)

     

    Also, as I mentioned in the original solution response...

    As for your Patch statement. All is good there except the Number value. If you are getting the information from a Choice column, then you will really only have values. If you have another source for the number values (such as a lookup), then this is easily added in.

    The above formula will have a result of 0 since your button text is a string that is non-numeric. If you need values for your buttons (numeric), then I would suggest putting them into your Items definition for the Gallery

     

    Also - Wasn't entirely clear from your original question if you wanted the users to be forced to "Unselect" a button before choosing another, or if they could choose any button regardless. 

     

    I've provided another sample app that properly demonstrates the use of the numeric value in your choices.  Also, I've accounted for the ability for a user to select any button they want, or to be forced to unselect the current button in order to choose another. (In PowerApps, Create and App or Open an existing App, then File->Open->Browse for downloaded file).

     

    Key areas to look at in the app:

       App - OnStart

       Gallery1 - Items, OnSelect

       Button1 - Fill, HoverFill

       HtmlText1 - HtmlText

     

    I hope this is clearer for you and helpful.


     

     

    Thankyou for this,

     

    However i dont think i explained myself very well, however after playing around with the app ill show you what i mean, ive left your example with the yellow fill and im using two gallery's below, one is called DumpGallery and the other called PitGallery. With buttons named Dumpbutton and Pitbutton, 

    1guy.png

    Both these new collections are loaded via the onstartapp:

     

    ClearCollect(
     buttonList, 
     {button:"SR1", value:1, selected:false},
     {button:"SR2", value:2, selected:false},
     {button:"LM1", value:3, selected:false},
     {button:"LM2", value:4, selected:false},
     {button:"LM3", value:5, selected:false},
     {button:"SRE", value:6, selected:false})
    
     ;
     ClearCollect(
     PitList, 
     {PitBut: {Value : "LM1"}, selected:false},
     {PitBut: {Value : "LM2"}, selected:false},
     {PitBut: {Value : "LM3"}, selected:false},
     {PitBut: {Value : "SR1"}, selected:false},
     {PitBut: {Value : "SR2"}, selected:false},
     {PitBut: {Value : "SRE"}, selected:false})
     ;
     ClearCollect(
     ButtonCollection,
     {ButtonText: "North Dump", IsClicked: false},
     {ButtonText: "South Dump", IsClicked: false},
     {ButtonText: "East Dump", IsClicked: false},
     {ButtonText: "West Dump", IsClicked: false}
    );
    Set(CurrentButtonText, Blank());

    However i am not able to get any of these buttons to patch into the sharepoint list (i made everything a choice column for convience)

     

    So i want when say the button LM1 is selected to send LM1 value into a choice column on sharepoint and if i want have the North Dump and LM1 and other buttons selected the onselect of the tic sends them all to sharepoint together?

     

     

    I think its probably easier to show the patch code

    If(
     Connection.Connected,
     Patch(
     'Haulage Log',
    	 Defaults('Haulage Log'),
    	 {
     Pit: {Value: Gallery1.Selected.Button1}, 
    'Dump Location: {Value: DumpGallery.Selected.DumpButton}

    } ), Collect( TESTCOLLECTION, { Pit: {Value: Gallery1.Selected.Button1} ,
    'Dump Location: {Value: DumpGallery.Selected.DumpButton} } ) ); Navigate(Screen1, ScreenTransition.None)

    the error i get when i try to patch is as follows,  

     

    the value column in the data source your updating expects a text type and your using a control type
     

    Also i can not for the life of me figure out why i cant copy and paste your html code and change the gallery etc and for it to work. (i take it, the patch functions patches the html not the gallery? or am i confused)

     

     

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Is the Gallery1 connected to your PitList collection or buttonList collection?

    Based on the formula you mentioned, I think there is something wrong with it.

     

    The Value property within the Pit column and 'Dump Location' column is required to provide a Text value, but the result the Gallery1.Selected.Button1 formula and DumpGallery.Selected.DumpButton formula returns a button control.

     

    Please consider modify your formula as below:

    1. If the Gallery1 connected to your PitList collection:

     

    If(
     Connection.Connected,
     Patch(
     'Haulage Log',
    	 Defaults('Haulage Log'),
    	 {
     Pit: {Value: Gallery1.Selected.PitBut.Value}, 
     'Dump Location': {Value: DumpGallery.Selected.ButtonText}
    
     }
     ),
     Collect(
     TESTCOLLECTION,
    	 {
     Pit: {Value: Gallery1.Selected.PitBut.Value} ,
    'Dump Location': {Value: DumpGallery.Selected.ButtonText} } ) ); Navigate(Screen1, ScreenTransition.None)

     

    2. If the Gallery1 connected to your buttonList collection:

    If(
     Connection.Connected,
     Patch(
     'Haulage Log',
    	 Defaults('Haulage Log'),
    	 {
     Pit: {Value: Gallery1.Selected.button}, 
     'Dump Location': {Value: DumpGallery.Selected.ButtonText}
    
     }
     ),
     Collect(
     TESTCOLLECTION,
    	 {
     Pit: {Value: Gallery1.Selected.button} ,
    'Dump Location': {Value: DumpGallery.Selected.ButtonText} } ) ); Navigate(Screen1, ScreenTransition.None)

     

    Please reference the column values from your corresponding collection rather than the button control itself.

     

    Best regards,

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

     


    @v-xida-msft wrote:

    Hi @Anonymous ,

    Is the Gallery1 connected to your PitList collection or buttonList collection?

    Based on the formula you mentioned, I think there is something wrong with it.

     

    The Value property within the Pit column and 'Dump Location' column is required to provide a Text value, but the result the Gallery1.Selected.Button1 formula and DumpGallery.Selected.DumpButton formula returns a button control.

     

    Please consider modify your formula as below:

    1. If the Gallery1 connected to your PitList collection:

     

    If(
     Connection.Connected,
     Patch(
     'Haulage Log',
    	 Defaults('Haulage Log'),
    	 {
     Pit: {Value: Gallery1.Selected.PitBut.Value}, 
     'Dump Location': {Value: DumpGallery.Selected.ButtonText}
    
     }
     ),
     Collect(
     TESTCOLLECTION,
    	 {
     Pit: {Value: Gallery1.Selected.PitBut.Value} ,
    'Dump Location': {Value: DumpGallery.Selected.ButtonText} } ) ); Navigate(Screen1, ScreenTransition.None)

     

    2. If the Gallery1 connected to your buttonList collection:

    If(
     Connection.Connected,
     Patch(
     'Haulage Log',
    	 Defaults('Haulage Log'),
    	 {
     Pit: {Value: Gallery1.Selected.button}, 
     'Dump Location': {Value: DumpGallery.Selected.ButtonText}
    
     }
     ),
     Collect(
     TESTCOLLECTION,
    	 {
     Pit: {Value: Gallery1.Selected.button} ,
    'Dump Location': {Value: DumpGallery.Selected.ButtonText} } ) ); Navigate(Screen1, ScreenTransition.None)

     

    Please reference the column values from your corresponding collection rather than the button control itself.

     

    Best regards,

     


    ahh that makes sense Smiley Happy Thankyou, ill finish this app and see if i run into anymore issues and mark as solved. Curiously do you know how i can make the checkbox lock? like Randy said? im curious as it looks like a great feature to add, id like to have the option that they have to unselect one and then reselect another too on a couple of these galleries?

     

    Also is there any issues if i have about 9 galleries on the one app?

     

     

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Do you want to add a Checkbox within the Gallery, then use Checkbox to determine if the corresponding button is selected?

     

    Please check and see if my response within the following thread would help in your scenario:

    https://powerusers.microsoft.com/t5/General-Discussion/Within-a-Gallery-Set-the-value-of-a-Textbox-Checkbox-quot/m-p/283593

     

    https://powerusers.microsoft.com/t5/Creating-Apps/Checkbox-for-quot-Select-all-quot-function-in-Gallery/m-p/253043

     

    Currently, there is no limits with the amount of Gallery controls you added within a canvas app. But for your app's performance, please do not add too many Gallery controls within your app.

     

    If you have solved your problem with previous solution I provided, please consider go ahead to click "Accept as Solution" to identifcy this thread has been solved.

     

    Best regards,

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

    @Anonymous 

    Sounds like you might be making some progress now.

    I have attached another round of the App sample to be closer to what you are trying to achieve.

    I have a couple questions for you:

    1) What do you mean by "checkbox lock"? 

    2) What type of column is Pit and 'Dump Location'?  Are these choice columns in SharePoint?

     

    Now we need to focus a bit on your Patch formula.  If you have these columns as choice columns then there is some more formula that we need to put in place.  

     

    BTW - don't worry about the HTML text in the sample app, it is just for demonstration/display of the information.  It's not the actual patch formula that you need.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    This is an awesome solution. The only step you missed was how you build your data source. I had to load your sample to learn this. Nice work, I really needed a solution like this for a current project.

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
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 207 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 150 Super User 2026 Season 2

Last 30 days Overall leaderboard