cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Oz
Level: Powered On

Run search when press enter

Hi all - I've found a similar question on here, but not the same.  I'm brand new to Power Apps and am trying the Org Browser example template.  Two questions please:

  1. How do I get the search from the front screen to run when a user presses the Enter key (rather than having to click on the search icon with their mouse)?; and
  2. How do I get it so when someone clicks on an email address, it launches their email client and creates an email?  In PowerApps I'm seeing an 'The function 'First' has some invalid arguments" error against the default code: Launch("mailto:"&First(EmployeeProfile).Mail).

Hope you can help and thanks in advance.  Oz

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Meneghino
Level 10

Re: Run search when press enter

Hi @Oz

 

Glad that you are now finding your way around.  As you can see from the OnSelect proerty of the search icon, what it does is to:

1) Load the search term into a collection called "SearchUser"

2) Navigate to the SearchScreen where the results are displayed

 

One alternative is to place the code that is in the OnSelect of the search icon in the OnChange property of the text input, but the problem is that it will probably be triggered every time a user enters a letter.

 

The solution I would suggest, if this can work, is to place the text input in the same screen as the gallery.

 

Then you can simply use this as the Items property of the gallery:

 

 

If(Len(TextInputSearchEmployee.Text) > 0, Sort(Filter(Office365Users.SearchUser({searchTerm:TextInputSearchEmployee.Text}), Len(GivenName) > 0), GivenName, Ascending))

 

If you decide to name the text input something else, then just substitute that name for TextInputSearchEmployee

 

I am suggesting this so that you avoid the navigation step, which is why a search icon is necessary.

 

If performance is bad, then you can try to set the DelayOutput property of the text input to true or false.  If false then it will search as soon as any change is made to the text, but may make the app hang a bit.  If true then it will wait, so that it will not search immediately but will hang less.

 

Hope this helps.

 

10 REPLIES 10
Meneghino
Level 10

Re: Run search when press enter

Hi @Oz

 

1) Check the OnSelect property of the search icon.  It probably has an UpdateContext type of syntax, where the context variable being updated is then used as the filter for the gallery displaying the data, in other words the Items property of the gallery.  What you need to do is to substitute the context variable in the filter expression of the gallery Items property with the value used by the UpdateContext expression.  This way you cut out the need to press the button.  However the app may slow down as the search is refreshed with every keystroke.

 

2) I assume that there is an issue with the EmployeeProfile collection/data source.  Either it is not spelled correctly or something else.  Try to substitute with an email string and see what happens.  You can use an HTML control to use the mailto: hyperlink.  I have not tried it, but it should work.  What I normally do is to send an email from within PowerApps by using the Office365 mail actoin in Flow.

 

Hope this helps

Oz
Level: Powered On

Re: Run search when press enter

Thanks @Meneghino.  I think I tried what you suggested for the search button, but it just went to the search results when you pressed 1 key so I gave up.  It seems to be a restriction of only having 'On Change' and 'On select' actions - if only there were an 'On enter' option.  I'm new to coding so am relying a lot on trial and error!

 

With regards other info., I tried changing Launch("mailto:"&First(EmployeeProfile).Mail) that was in the template from Microsoft to Launch("mailto:"&First(Employee).Mail) and it seems to work fine.

 

Thanks again, Oz

Meneghino
Level 10

Re: Run search when press enter

Hi @Oz

As you are new to PowerApps, be careful that there is no 'on enter' action.  What you need to do is to link the source of the items of you display gallery to be an expression of a source filtered by your search parameter.  You should find a few similar threads.

It takes a little getting used to, but that is the way PowerApps works.

Hope this helps.

Oz
Level: Powered On

Re: Run search when press enter

Thanks @Meneghino.  I think I'm being a bit dense!  I can't find the gallery you refer to anywhere.  The search icon on the home screen of the Org Browser app contains the following code:

 

Clear(PreviousEmployee);ClearCollect(SearchUser, TextInputSearchEmployee.Text); If(Len(TextInputSearchEmployee.Text) > 0,  Navigate(SearchScreen, Fade))

 

I think you're saying I have to put this in the gallery Items property ... which I can't find.  Have I understood you correctly and where would I find the gallery Items property please?

 

Thanks again, Oz

Oz
Level: Powered On

Re: Run search when press enter

Hi @Meneghino,

 

I've done some more reading about PowerApps and am starting to find my way around.  The On Select property of the search icon on the Home screen is:

 

Clear(PreviousEmployee);ClearCollect(SearchUser, TextInputSearchEmployee.Text); If(Len(TextInputSearchEmployee.Text) > 0,  Navigate(SearchScreen, Fade))

 

The Items value of the gallery on the Search screen is:

 

If(!IsEmpty(SearchUser), Sort(Filter(Office365Users.SearchUser({searchTerm:First(SearchUser).Value}), Len(GivenName) > 0), GivenName, Ascending))

 

I think you said to copy the first bit of code above into the second bit, but don't understand exactly which bit to change.  Also, is it a problem that the search box is on a different screen to the gallery?

 

Hope you can help as this is really frustrating me.  Thanks, Oz

Highlighted
Meneghino
Level 10

Re: Run search when press enter

Hi @Oz

 

Glad that you are now finding your way around.  As you can see from the OnSelect proerty of the search icon, what it does is to:

1) Load the search term into a collection called "SearchUser"

2) Navigate to the SearchScreen where the results are displayed

 

One alternative is to place the code that is in the OnSelect of the search icon in the OnChange property of the text input, but the problem is that it will probably be triggered every time a user enters a letter.

 

The solution I would suggest, if this can work, is to place the text input in the same screen as the gallery.

 

Then you can simply use this as the Items property of the gallery:

 

 

If(Len(TextInputSearchEmployee.Text) > 0, Sort(Filter(Office365Users.SearchUser({searchTerm:TextInputSearchEmployee.Text}), Len(GivenName) > 0), GivenName, Ascending))

 

If you decide to name the text input something else, then just substitute that name for TextInputSearchEmployee

 

I am suggesting this so that you avoid the navigation step, which is why a search icon is necessary.

 

If performance is bad, then you can try to set the DelayOutput property of the text input to true or false.  If false then it will search as soon as any change is made to the text, but may make the app hang a bit.  If true then it will wait, so that it will not search immediately but will hang less.

 

Hope this helps.

 

Oz
Level: Powered On

Re: Run search when press enter

Thanks @Meneghino - perfect!  The place I was getting confused was having the search box on a different screen to the results.  I've now simply added a button to the home screen which navigates the user to the search screen, and then used your suggested code for updating the search results whenever a letter is entered in the search box.

 

The next minor tweak I'd like to do is the following, and I can't find any threads about it ...

 

When a user clicks the search button on the Home screen it navigates them to the Search screen, but they then have to tap / click on the search input box to enter a search string.  Is there a way to get the button on the Home screen to take them to the Search screen AND put the cursor in the search input box so they can just start typing?  This would save an extra unnecessary click!

 

Thanks again in advance!  Oz

Meneghino
Level 10

Re: Run search when press enter

Hi @Oz

I am not aware of any action to put the cursor in a specific control.

The only thing I can suggest is to use the tab order to put the search box as first.

Oz
Level: Powered On

Re: Run search when press enter

Thanks @Meneghino.  I tried that, but it doesn't automatically put the cursor in there unfortunately.  I've raised an idea to see if they can add it as an option.  Thanks for all your help, it's made a real difference.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

SixthImage

Power Summit Australia 2019

August 20-23rd 2019

Users Online
Currently online: 34 members 4,234 guests
Please welcome our newest community members: