A new method addNotification has been added to to the client side API. This method can:
- Display a error or recommendation notification. In the earlier version the only option available was error notifications.
- It also allows you to specify and execute actions based on the notification. The new method not only display the notification, it also display 2 buttons:
- “Apply” to execute the action
- “Dismiss” to close the notification
Code
The following sample code will display recommendation notification if there are numbers in the “name” of the account. If the user clicks on “Apply” button, it will remove the numbers from the name and clear the notification. If the user clicks on “Dismiss” button, the notification will be closed. function addNotification() {
//get the name control
var myControl = Xrm.Page.getControl('name');
//get the name attribute
var accountName = Xrm.Page.data.entity.attributes.get('name');
//get the value name attribute
var accountNameValue = accountName.getValue();
//if the account name is null then return
if (accountName.getValue() == null) {
return;
}
//regular expression to find numbers
var r = /\d+/;
var s = accountNameValue.match(r);
//if match the display the message
if (s != null) {
var actionCollection = {
message: 'Remove the numbers from the name?',
actions: null
};
actionCollection.actions = [function () {
//remove the numbers
accountName.setValue(accountNameValue.replace(/[0-9]/g, ''));
myControl.clearNotification('my_unique_id');
}];
myControl.addNotification({
messages: ['Number/s in the account name'],
notificationLevel: 'RECOMMENDATION',
uniqueId: 'my_unique_id',
actions: [actionCollection]
});
}
}
Results
When the user clicks “Apply”, the system removes the number 7 from the name.
This functionality will be very useful in number of scenarios, for e.g. validating a field and recommending a value, moving the focus to specific tab or field, validating the field value on the parent entity, and opening the parent form to update the fields etc..
Great... I can think of 101 use to this new feature
ReplyDelete