Design a site like this with WordPress.com
Get started

Difference Between SetNotification and SetFormNotification

Ever found a form with only a notification and you struggled for hours to find where that field is ? #Dont_be_a_karan

In todays short article we will walk through two Javascript Functions that are used to set functions and compare the UI

SetFormNotification : https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/formcontext-ui/setformnotification

This function creates a notification however the limitation is that there is no control on the Notification, essentially that means the user is forced to find where she/he is going wrong , now this would be great if you have a small form with lets say a single tab but this isn’t ideal if you have a form with 5 tabs..

The syntax goes as – formContext.ui.setFormNotification(errorMessagePast, “ERROR”, notificationId);

And to remove this notification the syntax goes as – formContext.ui.clearFormNotification(notificationId);

Set Notification :

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setnotification

This is very similar to the Set form Notification however the key difference lies in the ability for the user to navigate to the problematic field. Additionally the Set notification property cannot be used to set up recommendations (INFO) or warnings.

The syntax goes as –  formContext.getControl(“args”).setNotification(errormessage,notificationId);

And to remove this notification the syntax goes as –  formContext.getControl(“args”).clearNotification(notificationId);

Comparing the UI of the two notifications –

If you look closely you will notice that the Set notification error highlights the field that has an error as well as the notification near the ribbon gives you the ability to navigate to the correct field where as the Set form notification error just gives you an error on the form.

Sample code – ( pre-requisite to create two fields named Set notification and Set form notification )

function sfn(executionContext) {
    var formContext = executionContext.getFormContext();
    var errorMessagePast =  "Form notification";
    var errorMessagePast1 =  "set notification";
    var y = formContext.getAttribute("kkit_setnotification");
    var notificationId1 = "_myUniqueId1";
    var x= formContext.getAttribute("kkit_setformnotification");
    var notificationId = "_myUniqueId";

        if(x.getValue()==null || y.getValue()==null)
        {
            if(x.getValue()==null && y.getValue()==null )
            {
        formContext.ui.setFormNotification(errorMessagePast, "ERROR", notificationId);
        formContext.getControl("kkit_setnotification").setNotification(errorMessagePast1,notificationId1);
            }
            if (x.getValue()!=null && y.getValue()==null )
            {
                formContext.ui.clearFormNotification(notificationId);
                formContext.getControl("kkit_setnotification").setNotification(errorMessagePast1,notificationId1);
            } 
            if( x.getValue()==null && y.getValue()!=null)
            {
                formContext.getControl("kkit_setnotification").clearNotification(notificationId1);
                formContext.ui.setformNotification(errorMessagePast, "ERROR" ,notificationId);

            }

           
         }
        else
         {
            formContext.ui.clearFormNotification(notificationId);
            formContext.getControl("kkit_setnotification").clearNotification(notificationId1);
         }
        
};

I hope this helps 😀 !

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: