Back to Basics # 43: Clear Form Notifications with Webresource in Dynamics CRM

Introduction:

In Dynamics 365 CRM to clear 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 clear form notifications using clearFormNotification if at all title was mentioned on the contact form.

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, in setFormNotification uniqueId parameter was provided as a string which will be written inside web resource to show error notification with the following syntax

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

As

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

as shown in the below figure.

Step 4:

After Step 3, to remove error notification from form whenever condition was met i.e., if user provides title then on change event of field Title we can write clearFormNotification- with the following syntax

formContext.ui.clearFormNotification(uniqueId)

As

formContext.ui.clearFormNotification(“JobTitleMandateNotification”);

as shown in the below figure

Step 5:

After Step 4, to show and clear error notification condition here is if at all title field is not filled then the following function should be called from onload event of contact form / contact form job title field change event with the below code

function jobtitlemandatorylogic(executionContext) {

    var formContext = executionContext.getFormContext();

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

    {

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

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

        if (jobtitle == null)

        {

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

        }

        else

        {

            formContext.ui.clearFormNotification(“JobTitleMandateNotification”);

        }

    }

}

as shown in the below figure

Step 6:

After Step 5, save and publish the web resource and open/refresh contact record and observe if there is no job title then error message will be shown on contact form load as shown in the below figure

Step 7:

After Step 6, if we provide Job title, then on change of job title field event, respective error notification gets cleared, clearly showed in console window 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 clearing notifications only, and the above function should be called from onchange event of contact title field & contact onload form event.
  3. Microsoft documentation found here

Conclusion: In this way, one can easily use clear form notifications in web resource to with the help of uniqueId in CRM Forms for all entities easily.

3 thoughts on “Back to Basics # 43: Clear Form Notifications with Webresource in Dynamics CRM

  1. Pingback: Back To Basics :Curated List of Articles in a Single Page – Common Man Tips for Power Platform, Dynamics CRM,Azure

  2. Pingback: Rewind February 2022 – Common Man Tips for Power Platform, Dynamics CRM,Azure

  3. Pingback: Rewind February 2022 - Microsoft Dynamics CRM Community

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 )

Facebook photo

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

Connecting to %s