Skip to content

Instantly share code, notes, and snippets.

@fjeldstad
Last active August 29, 2015 14:00
Show Gist options
  • Save fjeldstad/11193850 to your computer and use it in GitHub Desktop.
Save fjeldstad/11193850 to your computer and use it in GitHub Desktop.
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