cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bolin-stratus
Post Patron
Post Patron

Adding a Second Field to Search

My app currently searches the "Title" field but I want it to also search the "ID" field. The function is listed below.

 

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title, TextSearchBox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

 

How would I modify this to also allow searches for "ID"?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I finally got it working. This code is attached to the gallery and uses a filter to look for either Title or SFDC ID. It also performs a default, ascending sort on Title. 

 

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title,TextSearchBox1.Text)||StartsWith('SFDC ID',TextSearchBox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

Thanks to everyone who responded as I could not have arrived at this solution with your help. 

View solution in original post

13 REPLIES 13
Drrickryp
Super User II
Super User II

Hi @bolin-stratus,

You would add an "Or" condition to the filter.  

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title, TextSearchBox1.Text) || ID=Value(Textsearchbox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

@Drrickryp Thanks for your response.  The ID field is actually "SFDC ID" so I had to amend your code to:

 

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title, TextSearchBox1.Text) || ThisItem.'SFDC ID'=Value(Textsearchbox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

I also tried this but both threw errors.

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title, TextSearchBox1.Text) || 'SFDC ID'=Value(Textsearchbox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

 

Error message
function code error.PNG

 My app is already searching the 'Title' (Pursuit Name) field and I need to also search 'SFDC ID' (OPX Number).  I just couldn't find anything that would work.  Any recommendations are appreciated.

function code 3 fields.PNG

Try it without the Value() function 

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title, TextSearchBox1.Text) || 'SFDC ID'=TextSearchBox1.Text), "Title", If(SortDescending1, Descending, Ascending))

Thanks.  I tried the new code you recommended and the error is gone but it will not search. When I try a search on SFDC IS, iget nothing, but it still works when I searched by Title. 

Hi @bolin-stratus,

I tried it on my side and it works perfectly.  I can't see why it doesn't work for you.  Filtered on nameFiltered on name

 

Filtered on IDFiltered on ID

 

@Drrickryp I think I'm getting closer to a solution.  As a test, I replaced my original code where it was searching "Title" to searching "SFDC ID".  Notice that to get it wkg, I had to use "SFDC_x0200_ID" which happen to popup as a suggestion while editing code.

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith('SFDC ID', TextSearchBox1.Text)), "SFDC_x0020_ID", If(SortDescending1, Descending, Ascending))


I thought I could get your code wkg by using "SFDC_x0200_ID" but it isn't wkg.  What are the differences between "SFDC_x0200_ID" and "SFDC ID"? Any recommendations on editing the code? 

I see a "*1" in @Drrickryp's formula in the screenshot. Is this to change text into a number to match the Type for the ID field? I know you were using the Value() function to do the same thing, but you might try that.

 

And the _x0020_ is just a placeholder for spaces in a name that has to be rendered without spaces. You should be fine using 'SFDC ID' (single quotes), the way you were.

@TimRohr - Thanks for the clarification and suggestions. Regarding my earlier code involving the use of the Value function, I caught a typo for  TextSearchBox1 (see below). After correcting this, replacing Value with .Text*1 still failed to provide a solution and the Value function did not work either. 

 

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', StartsWith(Title, TextSearchBox1.Text) || 'SFDC ID'=Value(Textsearchbox1.Text)), "Title", If(SortDescending1, Descending, Ascending))


Is combining default sorting band search code a best practice or is it better to separate out the search code and attach to the search text box?  Alternately, do you have any recommendations on how to tweak the existing code? Any info is greatly appreciated.

 

Hi @bolin-stratus,

The sort should not have any effect on the filter.  Try separating the filter conditions and try filtering on just the 'SFDC ID' column.  Make sure that 'SFDC ID' is the actual column name.  The types have to match also, text with text and number with value.  Once you get that to work, add the other condition back in. 

SortByColumns(Filter('New DXC SharePoint Pursuit Site Request Form', 'SFDC ID'=Value(Textsearchbox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

 

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 (69,382)