web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Back to Basics # 42: Set Form Notifications with Webresource in Dynamics CRM

venkatsr Profile Picture venkatsr User Group Leader

Introduction:

In Dynamics 365 CRM to show form notifications, web resources of type JavaScript was used. Form context ui related client api reference can be used. As an example, contact form and contact entity record used to set show form notifications using setFormNotification.

Step 1:

Login to the required environment and select required solution [Contact Customizations Solution in this case] as shown in the   below figure.

Step 2:

After Step 1, select contact web resource in solution and click on Edit as shown in the below figure.

Step 3:

After Step 2, below code will be written on any function here handleOnLoad local function inside webresource to show information notification we use formcontext.ui as base object along with setFormNotification which requires few arguments message, level ,unique id to be passed with the following syntax

formContext.ui.setFormNotification(message, level, uniqueId);

.As an example to show information message on contact form below code can be used

var firstname= formContext.getAttribute(“firstname”).getValue();

                console.log(‘First name-‘+firstname);

                formContext.ui.setFormNotification(firstname+” : INFORMATION notification.”, “INFO”);

as shown in the below figure.

Step 4:

After Step 3, to show Warning notification below code can be used

formContext.ui.setFormNotification(“Mobile Phone number not filled – Warning notification.”, “WARNING”);

as shown in the below figure

Step 5:

After Step 4, to show error notification condition here is if at all title field is not filled then

var jobtitle=formContext.getAttribute(“jobtitle”).getValue();

                console.log(‘job title-‘+jobtitle);

                if(jobtitle==null)

                {

                    formContext.ui.setFormNotification(“Job title Mandatory- Error notification.”, “ERROR”);

                }

as shown in the below figure

Step 6:

After Step 5, entire code looks like below to show all kinds of notifications

var formContext=executionContext.getFormContext();

        if(formContext!==null && formContext!=’undefined’)

            {

                var firstname= formContext.getAttribute(“firstname”).getValue();

                console.log(‘First name-‘+firstname);

                formContext.ui.setFormNotification(firstname+” : INFORMATION notification.”, “INFO”);

                formContext.ui.setFormNotification(“Mobile Phone number not filled – Warning notification.”, “WARNING”);

                var jobtitle=formContext.getAttribute(“jobtitle”).getValue();

                console.log(‘job title-‘+jobtitle);

                if(jobtitle==null)

                {

                    formContext.ui.setFormNotification(“Job title Mandatory- Error notification.”, “ERROR”);

                }

        }

As shown in the below figure

Step 7:

After Step 6, save web resource and publish it and then open contact record and observe after loading the record all the notifications will be shown in the notification panel starting from information, warning, error levels as shown in the below figure

Note:

  1. Make sure to publish all customizations and upload JavaScript (js) file.
  2. Here I have concentrated more on showing notifications only, we can extend it by restricting to save record until error notification [Title] was filled in the above screen shot.
  3. Microsoft documentation found here

Conclusion: In this way, one can easily use set form notifications in web resource to show notifications in CRM Forms for all entities easily.


This was originally posted here.

Comments

*This post is locked for comments