Using JavaScript is a quite common approach for client side validation and interaction on the Microsoft Dynamics CRM forms. In many occasions we need to notify or warn the user about a condition or situation depending on certain values of some fields in the form. Normally you would use a JavaScript alert to show a dialog with the warning notification, this can be quite annoying for the users if they keep continuously facing this warnings.

Microsoft Dynamics CRM has a internal nice way of doing it by adding a yellow background warning message on top of the form, like in the picture below.


After a question on the Dynamics CRM Forums I’ve been playing a little bit with this an created a small JavaScript snippet that can be used to enable our client side code to achieve the same effect showing warning messages.

The code consist of a function called ‘addNotification’ that allows you to add a new notification message with the same visual style as the Dynamics CRM ones. This function uses the Notification area that is included on an Entity form to display the message with the same visual style.

Once you have added the declaration of the ‘addNotification’ function to the OnLoad you can call it either from the Onload or any OnChange event to provide warning messages to the user without using the typical JavaScript alert approach. The result will be the same as the one shown in the screen capture below.




Here is the code. Enjoy!

/*============== addNotification function =============

Adds a warning message on the top of the entity form using
the same visual style as Microsoft CRM

Params: message to be shown to the user

addNotification = function(message) {

var notificationHTML = '
' + message + '

var notificationsArea = document.getElementById('Notifications');

if (notificationsArea == null) return;

notificationsArea.innerHTML += notificationHTML; = 'block';

/*============= END addNotification function ===========*/

//Example of utilizations
addNotification('Some warning message that you want to show to the user ');



Originally published by Marco Amoedo