web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Gallery shows empty re...
Power Apps
Answered

Gallery shows empty results eventhough Search keyword exists

(0) ShareShare
ReportReport
Posted on by 195

I have a Textbox field "EventName" and Search button as in below screenshot. Clicking on Search button, I am populating the gallery with list items.

 

When I key-in any keyword in "EventName", it should search Event column in SharePoint. I have written below script in Items property under Gallery.

If(SearchButton.Pressed="True" && TextInput1.Text <> "", Search('DataSource',TextInput1.Text,"Event"))

 

Gallery shows empty results even-though, I have related keywords in my event column. Any technical advice would be helpful.

Img1.PNG

 

 

 

Categories:
I have the same question (0)
  • PowerAddict Profile Picture
    7,316 Most Valuable Professional on at
    How about giving it an else condition with something like this?

    If(SearchButton.Pressed="True" && TextInput1.Text <> "", Search('DataSource',TextInput1.Text,"Event"), 'DataSource')

    Also not really sure about your pressed condition but tey this out and let me know if it doesn't work.

    ---
    If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution. Thanks!

    Hardit Bhatia
    https://thepoweraddict.com
  • Kumar9024021 Profile Picture
    195 on at

    Hi @PowerAddict ,

     

    I tried. Search doesn't work. It always shows else condition. I think SearchButton.Pressed doesn't seem to work.

  • Community Power Platform Member Profile Picture
    on at

    @Kumar9024021 Button.Pressed toggles from true to false. You can see this if add a label and set it's Text property to SearchButton.Pressed then click the button a number of times.

     

    I'm confused about the process flow you are using to set your gallery. What code is in the OnSelect of the Search button? My guess is it creates a collection and this collection should be the Items property of your gallery, nothing else

  • Kumar9024021 Profile Picture
    195 on at

    Hi @Anonymous ,

     

    I tried another alternate way. On every textinput field OnChange, I used below formula.

     

    UpdateContext({searchTerm:TextInput1.Text })

    UpdateContext({searchTerm1:TextInput2.Text })

     

    In Gallery, Under Items property, I set it to below

     

    If(searchTerm <>"",Search('DataSource',searchTerm,"Event"),

    If(searchTerm1<>"",Search('Data Source ',searchTerm1,"Organiser"),'DataSource'))

     

    However, if i use above approach, there is no use of Search button. Its something like runtime search.

     

    May I know any other best way for search, because user may key-in search keyword inside multiple fields at same time.

    Search should show results accordingly. Any advice would be helpful. Also would like to use Search button, rather than runtime search.

     

    I am using my data source directly for search rather than collection. Any issues in using it directly ?

     

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @Kumar9024021 

     

    Based on two threads posted by you, I have got a basic understanding of what you are trying to do.

    https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Search-combined-with-multiple-fields-OnClick-of-Search-button/td-p/414465 
    https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Search-between-dates-Powerapps/td-p/414456 

    In case you want to filter the data only when the Search button is clicked, you can set the configuration as:

    Button -> 

    UpdateContext({searchTerm:TextInput1.Text, searchEventOrganiser: TextInput2.Text, searchSubmittedBy: TextInput3.Text, searchStatus: TextInput4.Text, EventFrom: DatePicker1.SelectedDate, EventTo: DatePicker2.SelectedDate, searchEventLocation: TextInput5.Text })

    This sets variable for all the input controls, these can be used to only update the gallery when the button is clicked.
    Using Button.Pressed, is not the right way to track the click of a button control. It only returns true when the button is pressed and it will return to false as soon as you release the button.

    Gallery -> 

    Filter(DataSourceName, StartsWith(Event,searchTerm) && StartsWith(Organiser: searchEventOrganiser) && StartsWith('Submitted By', searchSubmittedBy) && StartsWith(Status,searchStatus) && StartsWith(EventLocation, searchEventLocation) && EventDate > EventFrom && EventDate < EventTo)

    This should give you the desired results. Note: Here, I have used AND(&&) condition between the logic. In case you want to apply an OR(||) condition, please replace the symbol accordingly.

    If this differs, please share more details about the scenario that you are trying to build.

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Kumar9024021 Profile Picture
    195 on at

    Thanks for your prompt reply @yashag2255. Just a small query.

     

    I assume we are using Filter here rather than Search , because "StartsWith" will retrieve all results, similar as search function.

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @Kumar9024021 

     

    Yes that's correct. Filter is used to get the records based on multiple inputs for multiple fields whereas Search will operate on a single search keyword.

    Let us know if this does not resolve the issue.

     

    Hope this Helps!

     

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Kumar9024021 Profile Picture
    195 on at

    Hi,

     

    I tried below formula to populate the Gallery. However, i noticed that search doesn't work after using below formula . Morever I tried adding date condition check , it shows that it expects text field rather than date.

     

    Filter('datasource',StartsWith(Event,searchTerm)||StartsWith(Organiser,searchTerm1)|| StartsWith(Status,searchTerm2)|| StartsWith(Where,searchTerm3))

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hi @Kumar9024021 

     

    This will only work when the button is clicked. Based on the logic, button click set up the variable and the gallery is filtered.

    Can you share more details about the data type of the fields in the SP list?

    Please share more information about the errors that you are getting and where are they in the formula?

    Note: To check if the variables have been assigned properly. You can check them inside: View -> Variables -> Select Page -> Look for values.

     

    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Kumar9024021 Profile Picture
    195 on at

    Hi Yash@yashag2255 ,

     

    Search Button OnSelect

    UpdateContext({searchTerm:TextInput1.Text });UpdateContext({searchTerm1:TextInput1_2.Text });

    UpdateContext({searchTerm2:TextInput1_3.Text });UpdateContext({searchTerm3:TextInput1_4.Text });

    Gallery Items

    Filter('DS',StartsWith(Event,searchTerm)||StartsWith(Organiser,searchTerm1)|| StartsWith(Status,searchTerm2)|| StartsWith(Where,searchTerm3))

     

    When I used search earlier for single fields, I was able to get the search results for same datatype. All are mostly single line of text.

     

    Is there any if,else i can add in Items Gallery ?

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard