-
Notifications
You must be signed in to change notification settings - Fork 26
MobileCRM.UI.RoutePlan.onSave
rescocrm edited this page May 15, 2023
·
2 revisions
Binds or unbinds the handler for route save validation.
Bound handler is called with the RoutePlan object as an argument.
The RoutePlan context object contains property "errorMessage" that can be used to cancel save with an error.
Use suspendSave method to suspend the save process if an asynchronous operation is required.
Argument | Type | Description |
---|---|---|
handler | function(RoutePlan) | The handler function that has to be bound or unbound. |
bind | Boolean | Determines whether to bind or unbind the handler. |
scope | Object | The scope for handler calls. |
This example demonstrates how to validate the route entities before saving.
MobileCRM.UI.RoutePlan.onSave(function (routePlan) {
var visitEntities = routePlan.myRoute;
visitEntities.forEach(function (appointment) {
if (appointment.isNew && appointment.properties.scheduledon < new Date()) {
routePlan.context.errorMessage = "Visits can't be planned to past.";
}
});
}, true, null);
This example demonstrates how to perform asynchronous route entities save validation.
MobileCRM.UI.RoutePlan.onSave(function (routePlan) {
var handler = routePlan.suspendSave();
var dirtyEntities = routePlan.myRoute.filter(function (appointment) {
return appointment.isDirty;
});
// Perform additional asynchronous validation on entities that are about to be saved.
checkParentAccountAsync(dirtyEntities, function (errorMessage) {
if (errorMessage)
handler.resumeSave("Can't save the route: " + errorMessage);
else
handler.resumeSave();
});
}, true, null);