The Notify function displays a banner message to the user at the top of the screen.
The character limit for Notify function is 500 characters, and the default time for displaying message on screen is 10 seconds (10,000 milliseconds).
The notification will be displayed on screen until the user dismiss it manually or the timeout expires which defaults to 10 seconds.
Also, If you want to display the message for indefinite time of period until the user dismiss it then you can provide the timeout to 0.
There are four types of notifications that you can use to display the messages on screen using notify function as follows:
NotificationType.Error: It displays the message as an error.
NotificationType.Information: It displays the message as an informational. This is the default notification type.
NotificationType.Success: It displays the message as success.
NotificationType.Warning: It displays the message as a warning.
Syntax:
Notify( Message [, NotificationType [ , Timeout ] ] )
- Message – Required. This is the message to display to the user.
- NotificationType – Optional. Type of the message to display to the user. The default is NotificationType.Information.
- Timeout – Optional. Number of milliseconds to wait before automatically dismissing the notification. The default is 10 seconds (or 10,000 milliseconds). To display the message for indefinite time of period until the user dismisses it then you can provide the timeout to 0.
Using a Notify function
Lets add a blank screen then add the Text input control, go to Insert tab, and select Text input control.
Named it txt_password, and set it’s Text property to No value as shown below.
Similarly, add a Text label control.
Named it lbl_password and set it’s Text property to Password.
Let’s use the NotificationType.Information to show the information to the user when they just select the text box to enter the password.
On the Onselect property of Text input control write the below code.
Here, in Notify function, we have provided the message that we want to display, type of notification that is NotificationType.Information and timeout to 20 second.
Notify("Password must be alphanumeric", NotificationType.Information, 20)
Now, run the app. You can as soon as you just start typing the password. Power Apps displays you the informational message for 20 seconds.
If you want increase the duration of message, you can increase the time limit or set it to 0 for indefinite time of period until user dismiss it manually.
Note that, informational message is displayed in grey color with information icon.
Now, see the use of NotificationType.Warning and NotificationType.Success messages.
Let’s display the warning message when user enter the password in correct format and display the success message, if password is in correct format.
On the Onselect property of Text input control write the below code.
It checks, if the entered password is an alphanumeric then display the Success message otherwise display the Warning message.
If( IsMatch( txt_password.Text, "([A-Za-z]+[0-9]|[0-9]+[A-Za-z])[A-Za-z0-9]*" ), Notify( "Password is in correct format", NotificationType.Success, 20 ), Notify( "Password must be alphamueric", NotificationType.Warning, 20 ) )
Now, run the app. Enter the password in wrong format to see the Warning message.
Enter only letters in text box, and you can see it displays the Warning message when you enter the password and click outside of the text box.
Note that, Warning message is displayed in yellow color with the warning icon.
Now, enter the password in correct format that is alphanumeric.
You can see, it displays the Success message when you enter the password and click outside of the text box.
Note that, Success message is displayed in green color with the warning icon.
Now, we will use the NotificationType.Error to display an error message when password length is less then 8 characters.
Let’s write the below code on Onselect property of Text input control.
If( Len(txt_password.Text) < 8, Notify( "Minimum length of password is 8 characters", NotificationType.Error, 20 ) )
Now, run the app. Enter the password with the length less then 8 characters.
You can see, it displays an error message.
Note that, Error message is displayed in red color with the error icon.
Also Read..
Create a variables in Power Apps
ClearCollect function in Power Apps
Highlight selected item in gallery
Email validation in Power Apps
Sort Items in gallery Power Apps
Change Item color in gallery based on value
Creating a cascading dropdown lists in Power Apps