Notify or Alert function in Power Apps (Power Fx)

 Notify or Alert function in Power Apps (Power Fx)

Reference:  1   2   3

There are many types of notifications in Power Apps, such as,

      1. Message banners

  • A message banner is displayed at the top of the app that doesn't need to be dismissed.

          
      2. Dialog boxes.          
  • A dialog box is displayed on top of the current screen.        
  • Two buttons are provided: a confirm button and a cancel button, which default to localized versions of "OK" and "Cancel" respectively. 
  • The user must confirm or cancel before the dialog box is dismissed and the function returns
Next, let's talk about how to create above notifications.

1. Notify

The Notify function displays a banner message to the user at the top of the screen. The notification will remain until the user dismisses it or the timeout expires which defaults to 10 seconds.

Syntax

NotifyMessage [, NotificationType [ , Timeout ] ] )

  • Message – Required. Message to display to the user.
         The character limit for Notify function is 500 characters.
  • NotificationType – Optional. Type of the message to display from the table above. The default is NotificationType.Information.
              Examples:
               
                           Info:   Notify( "Hello, World" )



                           Error:  Notify( "Hello, World", NotificationType.Error )



Success:    Notify( "Hello, World", NotificationType.Success, 0 )


                               With a 0 timeout, the notification will only be dismissed by the user or by pressing the button again.
  • Timeout – Optional. Number of milliseconds to wait before automatically dismissing the notification. The default is 10 seconds (or 10,000 milliseconds). The notification will be displayed indefinitely with a Timeout of 0.
example:     Notify( "Hello, World", NotificationType.Warning, 4000 )

Notify( "Hello, World", NotificationType.Success, 0 )

                   

2. Confirm

The Confirm function displays a dialog box on top of the current screen. Two buttons are provided: a confirm button and a cancel button, which default to localized versions of "OK" and "Cancel" respectively.

At this time, the Confirm function is only available when writing Power Fx commands for model-driven apps.

Syntax

ConfirmMessage [, OptionsRecord ] )

  • Message - Required. Message to display to the user.
  • OptionsRecord - Optional. Provide option settings for the dialog box. Not all options are available on every platform and are handled on a "best effort" basis.     


Examples:

1. If( Confirm( "Are you sure?" ), Remove( ThisItem ) )
    Confirm returns true if the confirm button was selected, false otherwise.


2. Same dialog as the first example, but adds Title option.

If( Confirm( "Are you sure?", {Title: "Delete Confirmation"} ), Remove( ThisItem ) )

         

3. Adds ConfirmButton and CancelButton options.

Set( FavColor, If( Confirm( "What is your favorite color?", { ConfirmButton: "Red", CancelButton: "Green" } ), "Red", "Green" ) )
      

4. Displays a message much like the Notify function does, but is modal and requires the user to select a button to proceed.

Confirm( "There was a problem, please review your order." )

  • Use when it's important that the user acknowledges the message before proceeding. 
  • In this situation, which button was selected isn't important and the result isn't checked.
                     

No comments:

Post a Comment