cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

 

 

 

17 REPLIES 17

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 ?

 

Hey @Kumar9024021 

 

Just so we are on same page, can you confirm below details:

1) You have inputs on the top and you want to filter based on them. The results in the gallery will only change when the button is clicked.

2) The StartsWith will only get the results where the value starts with the assigned variable.

Search operates on getting the results where the value exist even in the substrings.

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

When you are using this formula, are you getting any records when the button is clicked?

If no, check the variable value from View -> Variables -> then check if the variables hold the correct value.

If yes, but incorrect records, try taking baby steps in building this expression, like:
Filter('DS',StartsWith(Event,searchTerm))

Try adding all the filters one by one and observe the pattern.

 

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 @yashag2255 ,

 

Got your point. I noticed that when I key-in all the fields (Event,Organizer,Status,Where), gallery results shows fine as expected using below formula.

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

I tried searching by keying-in only the Event textbox and left all 3 blank. Gallery results show me unexpected results. Screenshot below. When i search for ESR, it should show only ESR. But it shows with keyword "UAT" events, also despite using || in formula

Img4.PNGImg5.PNG

Hey @Kumar9024021 

 

That is happening because StartsWith considers search text ""(blank) as a valid input. To resolve this, you can update the expression as:

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

 

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 @yashag2255 ,

 

Thanks for your quick response. Search works fine now for text fields. However for date fields, I notice that search still doesn't work using below formula.

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)||When>DatePicker1.SelectedDate&&When<DatePicker1_1.SelectedDate))

 

I crosschecked the dateformat with datasource. Its same MM/DD/YYYY format. PFB screenshot. For textfields, I am storing the selected value in Search button OnSelect. Should we need to do same for dates ? I assume we have DatePicker. Selected property for that.

 

Img1.PNGImg2.PNG

 

 

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

Hi Yash @yashag2255 ,

 

As requested, I have made the changes below for OnSelect to maintain consistency. I noticed that Filter('DS', When>EventFrom&&When<EventTo) works perfectly fine, without any issues.

 

However when combined with other fields like below, it cease to work. It always returns empty results in Gallery.

 

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

 

Date format also crosschecked at all places. Its MM/DD/YYYY format.

 

 

Hi @Kumar9024021 

 

This is not working because of the bracket misplacement, please update the query as:

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

 

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
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

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

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Kudoed Authors
Users online (23,862)