Wednesday, April 28, 2010

MSCRM: Create Custom Warning Messages

Microsoft Dynamics CRM has a internal way of adding a yellow background warning message on top of a form. If you have the need to create a custom warning, you can use the code below to add a warning message that you design. This can be added to the onLoad event or field onChange event.

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

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

Params: message to be shown to the user


addNotification = function(message) {
var notificationHTML = '<DIV class="Notification"><TABLE cellSpacing="0" cellPadding="0"><TBODY><TR><TD vAlign="top"><IMG class="ms-crm-Lookup-Item" alt="" src="/_imgs/error/notif_icn_crit16.png" /></TD><TD><SPAN>' + message + '</SPAN></TD></TR></TBODY></TABLE></DIV>';

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

You can change the message to make it fit your needs or make it appear based on a field value.

No comments: