Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shims for form-level notifications in Microsoft Dynamics CRM 2011 (pre/post UR12) compatible with the notifications API from CRM 2013.
// Notification shims for Dynamics CRM 2011 (both pre and post UR12).
// The API is identical to the native (supported) notifications in
// Dynamics CRM 2013. Please note that calling undocumented JavaScript functions
// is not officially supported by Microsoft, which makes these shims
// "unsupported". But since the API is compatible with 2013 the upgrade path
// is straightforward (just remove the code completely, or leave them if you
// prefer - either should be fine).
if (typeof(Xrm.Page.ui.clearFormNotification) === "undefined") {
Xrm.Page.ui.clearFormNotification= function(messageId) {
var crmNotifications =
typeof($find) === "function" && $find("crmNotifications") ?
$find("crmNotifications") :
document.getElementById("crmNotifications");
if (crmNotifications && typeof(crmNotifications.SetNotifications) !== "undefined") {
crmNotifications.SetNotifications(null, messageId);
} else {
throw "Unable to implement shim for Xrm.Page.ui.clearFormNotification.";
}
};
}
if (typeof(Xrm.Page.ui.setFormNotification) === "undefined") {
Xrm.Page.ui.setFormNotification = function(message, level, messageId) {
if (typeof(Xrm.Page.ui.clearFormNotification) === "function") {
Xrm.Page.ui.clearFormNotification(messageId);
}
var crmNotifications =
typeof($find) === "function" && $find("crmNotifications") ?
$find("crmNotifications") :
document.getElementById("crmNotifications");
if (crmNotifications && typeof(crmNotifications.AddNotification) !== "undefined") {
var levelMap = {
"ERROR": 1,
"WARNING": 2,
"INFO": 3
};
crmNotifications.AddNotification(messageId, levelMap[level], messageId, message);
} else {
throw "Unable to implement shim for Xrm.Page.ui.setFormNotification.";
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.