This Javascript snippet on the Street field displays the yellow message the top:
function NotificationTop (msg,type) {
Xrm.Page.ui.setFormNotification(msg, type);
}
I love the customer experience of this message and once it has been added as a Library via Web Resource, it can be reused on many fields by adding it as a Form Library on your form, then implementing it on a field by:
With that all said, I would like to improve it to want it to behave similar to what happens when you try to advance in a Business Process Flow without providing the required fields. It has two features:
How would that Javascript need to change to accommodate 1 thru 3 above?
*This post is locked for comments
Thanks, Guido. That, together with putting the parameters in, did the trick!
BEAUTIFUL!!!! I get so excited when things like this work. ;-)
Thank you so much!!
I guess you are missing the function arguments.
Try this code :
function DisplayNotification(message,type,id) {
var time = 3000; //Display time in milliseconds
//Display the notification
Xrm.Page.ui.setFormNotification(message, type, id);
//Wait the designated time and then remove
setTimeout(
function () {
Xrm.Page.ui.clearFormNotification(id);
},
time
);
}
And this configuration on the field :
I tested it on CRM 2016 (works like a charm) but it should work on CRM 2013/2015.
Best,
Boris T
My onchange event looks like this:
function DisplayNotification() {
var time = 3000; //Display time in milliseconds
//Display the notification
Xrm.Page.ui.setFormNotification(message, type, id);
//Wait the designated time and then remove
setTimeout(
function () {
Xrm.Page.ui.clearFormNotification(id);
},
time
);
}
And
BUT ... absolutely nothing happens on change.
In fact, you must use the notification id if you want to use the clearNotification method.
You may check the MSDN documentation : msdn.microsoft.com/.../gg327828.aspx
In your case, you might add an argument (notificationId for instance), and you use it as described in the MSDN link.
Best,
Boris T.
Regarding "clears after X seconds", I modified the JS so it could receive parameters like this:
function DisplayNotification() {
var time = 3000; //Display time in milliseconds
//Display the notification
Xrm.Page.ui.setFormNotification(message, type);
//Wait the designated time and then remove
setTimeout(
function () {
Xrm.Page.ui.clearFormNotification();
},
time
);
}
And I passed in two parameters on the Event Handler.:
'Message','WARNING'
I figured I could drop id since it's on the field it needs to function on.
But nothing happens. Rookie, I am.
This is what it was before my modification:
function DisplayNotification() {
var message = "Useful message to the end user";
var type = "INFO"; //INFO, WARNING, ERROR
var id = "Info1"; //Notification Id
var time = 3000; //Display time in milliseconds
//Display the notification
Xrm.Page.ui.setFormNotification(message, type, id);
//Wait the designated time and then remove
setTimeout(
function () {
Xrm.Page.ui.clearFormNotification(id);
},
time
);
}
Thank you, Boris. I will study.
Hello Deb,
1. "Clears after # seconds" : you can use the Javascript function "setTimeout", combined with the clearNotification method. Check this blog article, with an example of what you want :
2. "Has a X to clear it on demand" : I don't think there is a supported way to do this. As a supported workaround, you may add a custom button in the command bar that clears notifications on the form.
3. "Not appear on create" : you can use the function Xrm.Page.ui.getFormType() (documented on MSDN here : https://msdn.microsoft.com/en-us/library/gg327828.aspx#Anchor_5 ) to know if you are in creation or modification mode.
Best,
Boris
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156