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 / Auto fill form with fi...
Power Apps
Answered

Auto fill form with first element in Gallery

(0) ShareShare
ReportReport
Posted on by 71

Hi,

 

I have a screen with a form and a gallery. The gallery can be filtering and changed depending on different tabs being clicked. I have a problem where on start of my app my form is not filled by the first element of the gallery and if I switch tabs (meaning some items in the gallery are not shown anymore) the form is still filled with the previously clicked item and not the first new item in the filtered gallery.

 

To summarize, I just want the form to be auto filled by the first item in the gallery when I switch tabs (the tabs are buttons) instead of having to actually click the gallery items.

 

Thanks in advanced if anyone has a solution!

Categories:
I have the same question (0)
  • Spamrancher Profile Picture
    345 on at

    I would capture the record in a variable and then every time you click a button, whatever the OnSelect of the button is doing to filter your data, grab the First() of that data into your variable. Set the form data to your variable.

  • ash15 Profile Picture
    71 on at

    So, I do already capture the record. What I do is filter the Gallery through its item's property and then for the OnSelect property I do Set(varSelected, ThisItem); and set the item property of the form to varSelected.

     

    Then what I try is for each tab (button) which changes the parameters to filter by, I have in their OnSelect Set(varSelected, First(Gallery.AllItems); to get the first item of the new filtered gallery. However, it does not seem to work.

  • Spamrancher Profile Picture
    345 on at

    What does "it does not seem to work" mean? Is it not changing the value? Rather than using Gallery.AllItems, I would retrieve the record from the data source as you filter the gallery. I want to say I've had an experience with AllItems where the gallery does not get new data before the variable is set. I think the platform executes the GetRows command for the gallery but does not wait for the data to be retrieved prior to executing the Set statement. If I recall, I got around that by adding a 3 second timer control and getting the variable at the end of the timer. I would encourage you not to go that route unless you absolutely have to. Try and get the data directly from the source first. You might be able to use a With() function to filter the gallery and set the variable using the same data filter.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ash15

    Whatever the items property of your gallery is in the default property of the gallery, wrap it in First(). Set the item property of the form to: LookUp(datasource, ID=Gallery1.Selected.ID)

    Replace Gallery1 with the name of your gallery. No need for a variable. 

  • ash15 Profile Picture
    71 on at

    Sorry, but this does not work either. Wrapping first on the items property of my gallery would mean that only the first item of the gallery is actually shown. I want it that the first item of the gallery is automatically selected and displayed on a corresponding view form. Here's my item code for my Gallery if it my help to see (sorry if it's messy I'm new to powerapps).

    Filter(
    Sort(
    If(
    IsBlank(someVar) || clickedTab1,
    Filter(Filter(Data,StartsWith(Param1, SomeValue), Field = Input),
    clickedTab2,
    Filter(Filter(Data,StartsWith(Param2, SomeValue), Field = Input)),

    Filter(Filter(Data,StartsWith(Param3, SomeValue), Field = Input))),
    Date,
    Sort.Descending
    ),
    StartsWith(Field, SearchInput)

    I feel as if I possibly misunderstood what you said though, please correct me if I'm wrong.

  • ash15 Profile Picture
    71 on at

    Sorry, by "it does not seem to work" I mean that the form does not change to the approximate item once I click the tab. The form only changes if I click on an item. I'll try to look into the With() function.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ash15 

    Yes, you did misunderstand.  Please post your gallery's  Items property and the name of your gallery.

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @ash15 

    Rewriting your gallery items property

     

     

    With({_items: Filter(
     Sort(
     Data, Date,Descending
     ),IsBlank(SearchInput.Text)|| StartsWith(Field, SearchInput.Text),
     condition1:IsBlank(someVar) || clickedTab1, 
     condition2: clickedTab2 
     },
     If(
     condition1: Filter(_items, StartsWith(Param1, SomeValue), Field = Input),
     condition2: Filter(_items, StartsWith(Param3, SomeValue), Field = Input),
     _items
     )
    )

     

     

    Default property for the gallery:

     

     

    With({_items: Filter(
     Sort(
     Data, Date,Descending
     ),IsBlank(SearchInput.Text)|| StartsWith(Field, SearchInput.Text),
     condition1:IsBlank(someVar) || clickedTab1, 
     condition2: clickedTab2 
     },
     First(
     If(
     condition1: Filter(_items, StartsWith(Param1, SomeValue), Field = Input),
     condition2: Filter(_items, StartsWith(Param3, SomeValue), Field = Input),
     _items
     )
     )
    )

     

    Item property of form:

      LookUp(Data, ID=Gallery.Selected.ID)  // replace Gallery with the actual name of your gallery.

     

  • ash15 Profile Picture
    71 on at

    Thank you so much I've been looking for a solution for so long this helped out!

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    You are welcome!You are welcome!

     

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 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 136 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 109 Super User 2026 Season 2

Last 30 days Overall leaderboard