cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
WillyD44
Kudo Commander
Kudo Commander

Resetting Gallery Selection Formula - Why does this work?

I read a thread on this PowerApps user forum that helped me acheive my desired end state...but I DON'T KNOW WHY IT WORKS and it's killing me. 🙂  

 

I want to set the value of a Gallery to not have any items in the gallery selected...in essence, show ALL gallery items.  This in turn affects how my table displays data as my table control is set to show only the row of data that corresponds to the Gallery selection.  But...what if the user says, "I don't want to look at a single record in the table any longer.  I want to see all table records."  At this point, I need to clear the Gallery.Selected value so that nothing is selected, which in turn will drive my table to show all records. 

 

A picture is worth a thousand words.  This sould tie things together.  

 

In the below image, the user selects Hull (Gallery1) in the Facility list.  Hull then shows in the Facility Details Table (Table Control whose data source is a SharePoint list).  

 

ResetSelectionButtonScenario1.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

But now, the user wants to reset the selection in the Facility to list to NONE...or BLANK.  The user wants all the facilities to show.  So, the user clicks the Reset Selection button and sure enough, the selection in Gallery1.Selection goes to BLANK and he is able to see all table records now.   See below screenshot, then see my question below that. 

 

ResetSelectionButtonSyntax.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Last detail...Gallery1 (Facility list, far left column)...Gallery1's Default property is set to: ResetButton.

 

What I don't understand is why the OnSelect property formula has to be the way it is.  I would have thought it should have been like this:

 

OnSelect = UpdateContext({ResetButton:{}})

 

If I use the property formula above, the Reset Selection Button works one timeAfter that it does not work.  

 

 

Why does the property have to be set to what the screenshot above shows to work?  In the event the screenshot does not show the working property formula well, here it is:

 

OnSelect = UpdateContext({ResetButton:Gallery1.Selected});UpdateContext({ResetButton:{}})

 

Hopefully someone can help.  It won't do me much good to have a formula stashed away with no understanding of how to use it, change it, improve it for different scenarios, etc. 

 

Bill

1 ACCEPTED SOLUTION

Accepted Solutions
Mike8
Memorable Member
Memorable Member

Hello,

OnSelect = UpdateContext({ResetButton:{}})
This works the first time because the default property of the gallery is set to an empty record ---> {}.
Before it wasn't an empty record and it changed to an empty record. 🙂
If you try to press it again, it will not work because the second time you set the ResetButton variable from {} to {}. So, it doesn't change. If the ResetButton doesn't change powerapps doesn't trigger the default property.

OnSelect = UpdateContext({ResetButton:Gallery1.Selected});UpdateContext({ResetButton:{}})
This works every time because in the same expression, you set the ResetButton to a value (Gallery1.Selected) and then you set it to an empty record. So, the ResetButton changes and powerapps triggers the default property.

To sum up, this is how powerapps works. You need to change the variable in the default property in order to trigger and apply the default value on the gallery.

View solution in original post

9 REPLIES 9

I don't know which thread you're referencing to so it would be helpfull to also know how your ResetButton is set. Is it like this?

Gallery1.OnSelect=UpdateContext({ResetButton: Gallery1.Selected})

And then your second gallery uses it for filtering the content?

Mike8
Memorable Member
Memorable Member

Hello,

OnSelect = UpdateContext({ResetButton:{}})
This works the first time because the default property of the gallery is set to an empty record ---> {}.
Before it wasn't an empty record and it changed to an empty record. 🙂
If you try to press it again, it will not work because the second time you set the ResetButton variable from {} to {}. So, it doesn't change. If the ResetButton doesn't change powerapps doesn't trigger the default property.

OnSelect = UpdateContext({ResetButton:Gallery1.Selected});UpdateContext({ResetButton:{}})
This works every time because in the same expression, you set the ResetButton to a value (Gallery1.Selected) and then you set it to an empty record. So, the ResetButton changes and powerapps triggers the default property.

To sum up, this is how powerapps works. You need to change the variable in the default property in order to trigger and apply the default value on the gallery.

Mike8...brilliant!  Great, clear and detailed explanation.  Thank you for taking time to answer my question. 

 

Best regards,

Bill

Hi,

Thanks for bringing this function up in the forums. 

May I suggest an alternative I've discovered that has less overhead?

I discovered it mainly out of your suggestion not quite working for my app's gallery.

 

Simply, I want to select a name from a gallery list and have this trigger the displaymode on a button from disabled to edit essentially not allowing the button to activate without first selecting a name from the list. In working through this, I found the below formulas work to deselect the name in the list and/or start with no name selected when you navigate to the screen.

 

Set the Gallery1.Default to {}        < an empty record

Set the ResetButton.OnSelect to Reset(Gallery1)        < resets the gallery to default

 

 

Thanks, @RussW  !

 

Using the Reset(NameOfMyGallery) method (aka formula) WORKS.  This is surprising since (currently) PApps galleries do not have a Reset property.  But hey, I'll take it.  It sure is easier than using the default property of the gallery via a toggled context variable.

Thanks and kudos to Mike8.  I've been working with PowerApps for the past 4 months and consider myself fairly knowledgeable.  In my application, users can make a selection from a drop-down and their selected value determines the contents of a Gallery.  The contents of the drop-down and the gallery come from SharePoint lists.  This is a very common scenario where the parent-child relationship is represented via two SharePoint lists. You select the parent ID value from the drop-down and the list of dependent records are displayed in the Gallery.

 

I was completely unable to control the default value of the Gallery. PowerApps would get the Gallery default value correct on the first display of the screen. However, the "child" gallery would not move to the correct default record the next time the user selected a value from the drop-down. I was going crazy and was ready to give up completely on PowerApps and look for some other solution. But Mike8 made a simple statement that woke me up.  His statement "To sum up, this is how powerapps works. You need to change the variable in the default property in order to trigger and apply the default value on the gallery."  I suddenly got it. There are probably many ways to accommodate PowerApps to trigger the updated default value on the Gallery. I switched to using a collection for the Gallery items property instead of using Filter directly from the SharePoint list. The collection is created/re-created using the drop-down control on-change event. Very simple. This pernicious problem is now solved. I'm going to continue to use PowerApps.

I am glad I could help @larry_nSightMgt.
The community is really helpful and active and if you have more questions I am sure someone can also help you next time. 🙂

 

Hi

Any update on the same.

Thank you

Few years removed but I still found this post very helpful to reset my gallery to not just be deselected, but also scroll to the top (maybe there's a better way?).

 

Thought I would share my variation to get both:

OnSelect = UpdateContext({cvResetGallery:Blank()}); Reset(Gallery1); UpdateContext({cvResetGallery:{}})

Key for me was to change the Gallery Default to nothing using Blank() (aka. Null) so that it auto selects the first entry and would force the reset to bring it back to the top of the long list if the user has scrolled down.

Then it updates the context variable back to an empty record so that there is nothing selected.

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