Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
9k views
in Power Apps by 2 2 3

Hi, I have built a login screen using PowerApps that read from the SharePoint list, I want to show an error message and reset the textbox if the user enters an invalid user name and password.

The below formula works for the reset correctly but not show the error message,

If(
    LookUp(
        Login,
        Title = txtUserName.Text,
        Password = txtPassword.Text
    ),
    Navigate(success), Reset(txtUserName), Reset(txtPassword) Notify( "Please write Correct User name and Password", NotificationType.Error ))

Also, when I try to show the error message in a label it doesn't work as expected.! any help on how I can perform multiple actions to reset textbox value and show an error message in PowerApps Formula?


2 Answers

2 like 0 dislike
by 48 54 94
selected by
 
Best answer

You seem to misunderstand the If condition in Power Apps

In PowerApss, the syntax of the if condition should be

If( Condition, ThenResult [, DefaultResult ] )
  • If the function tests one or more conditions until a true result is found, so ThenResult section will be executed.
  • If no condition evaluates to true a DefaultResult is returned.
  • If you don't specify the DefaultResult argument, a blank is returned.

So In your case, you have to check if the provided information is correct it should navigate to the Success screen otherwise, it should do three actions

  1. Print error message.
  2. Reset the user name textbox.
  3. Reset the password textbox

So in your formula, you should use multiple & to perfrom multiple actions in the else section as below :

If(
    LookUp(
        Login,
        Title = txtUserName.Text,
        Password = txtPassword.Text
    ),
    Navigate(success), Notify( "Please enter  Valid user name and Passwords", NotificationType.Error )&Reset(txtUserName)&Reset(txtPassword))

Output

show error message in power apps


Nester-IF in PowerApps

If you have multiple conditions, and you would like to use Nested IF in the PowerApps formula, you have to use the below syntax:

If(Condition, ThenResult, condition, ThenResult, condition, ThenResult[, DefaultResult ])

Read more at If and Switch functions in Power Apps

0 like 0 dislike
by 163 204 403

Show error message in PowerApps

In Power Apps, You can use Notify function to display notifications in PowerApps such as success messages, warning messages, error messages, information messages, and so on.

Notify function in PowerApps

Notify( Message , NotificationType.Error, Timeout)

display error message in PowerApps

Note: The character limit for Notify function is 500 characters. and the PowerApps notify position is at the top of the screen.

For more details, please check

See also How to use PowerApps notify function?

If you don’t ask, the answer is always NO!
...