Many out of the box CRM entities include their own special functionality. Sometimes this functionality is in line with our business needs and sometimes it is not.
Of course it’s great when it is. But on those occasions when it is not, we are forced to make a choice. We can choose to ignore the unwanted function, even if it occasionally interferes with our own business process. We can choose not to use a built-in entity entirely in favor of using a custom entity, but this generally means we must re-implement a lot of built-in functionality using client-side code and/or plugins, etc, just so that we don’t have to worry about any of the unwanted functions.

Here is a little trick that might help make this choice a little easier. What if we have a way to remove some of the standard form error notifications that often appear on out of the box entities? Here are a couple examples of what I’m referring to:


Those messages are triggered by built-in functionality that we have no control over. So, if your business model disagree’s with that built-in logic, there is nothing you can do to prevent or change it. Until now!

Since CRM 2013 was released, form notifications have been exposed to us as part of the supported Xrm context object. The only method we need in order to remove a notification from a page is:
Xrm.Page.ui.clearFormNotification(id);

Of course, this requires that we know the id of the notification we wish to remove. Unfortunately these built-in notifications get a random id each time the form is loaded, so it’s not as simple as getting the id, and hard-coding it into your code. Instead, we have to find it at runtime when the page loads. Fortunately, it’s not so difficult to do. Looking at the notification object in question, the only thing available to uniquely identify it is the error text itself. So we just check all the notifications on the page, and see if any of them are a match. This is all you need to run onLoad of the form:

var notifications = document.getElementsByClassName("Notification"); // List of all Notifications on the form
var errorText = 'At least one recipient does not have an email address or is marked as "Do Not Allow" email.'; // Error text we are looking for (must be exact match)

for (var i = 0; i < notifications.length; i++) { // Loop through all the Notifications if (notifications[i].textContent == errorText) { // Match based on the innerText equals the error message var notificationId = notifications[i].getAttribute("notificationid"); // This is NotificationId we are looking for Xrm.Page.ui.clearFormNotification(notificationId); // Hide the Notification using the supported method break; // Done } }

From there, we can either replace the message with one of our own based on our own business logic. Or don’t replace it at all, if it is not something your business is concerned about.