cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kumar9024021
Helper V
Helper V

Gallery shows empty results eventhough Search keyword exists

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hey @Kumar9024021 

 

Its good that we are able to make the text fields work. Now, let do the same for the date type field.

It would be consistent to set the variable on Button click as if you use DatePicker.SelectedDate, the results in gallery will automatically refresh even if you do not click the button.

Also, set the format property of the DatePicker as "MM/DD/YYYY"


You can set the values as:

Button OnSelect -> UpdateContext({EventFrom: DatePicker1.SelectedDate, EventTo: DatePicker2.SelectedDate})

Gallery -> Items ->
Filter('DS',If(Len(searchTerm)>0,StartsWith(Event,searchTerm))||If(Len(searchTerm1)>0,StartsWith(Organiser,searchTerm1))||If(Len(searchTerm2)>0,StartsWith(Status,searchTerm2))||If(Len(searchTerm3)>0,StartsWith(Where,searchTerm3))|| And(When>EventFrom, When<EventTo))

If this does not work, try:

Filter('DS', When>EventFrom&&When<EventTo)

Can you confirm if this is a date type column in SP list? If it is not, then you might want to update the expression to:

Filter('DS', DateValue(Text(When,"MM/DD/YYYY")) >EventFrom && DateValue(Text(When,"MM/DD/YYYY"))<EventTo)

You can add the text filters later, first lets filter on dates.

 

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!

View solution in original post

17 REPLIES 17
PowerAddict
Super User II
Super User II

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

Hi @PowerAddict ,

 

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

@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

Hi @Eelman ,

 

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
Dual Super User II
Dual Super User II

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-field... 
https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Search-between-dates-Powerapps/td-p... 

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!

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.

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!

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))

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!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (59,614)