Clear Form Notifications With Webresource In Dynamics CRM

Introduction

In Dynamics 365 CRM to clear form notifications, web resources of type JavaScript were 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.

Clear Form Notifications with Webresource in Dynamics CRM

Step 2

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

Clear Form Notifications with Webresource in Dynamics CRM

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");

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");

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

Figure 5

Clear Form Notifications with Webresource in Dynamics CRM

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

Clear Form Notifications with Webresource in Dynamics CRM

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.

Clear Form Notifications with Webresource in Dynamics CRM

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 with the help of uniqueId in CRM Forms for all entities easily.


Similar Articles