We have recently faced a problem while reloading the form after save MS CRM Entity form. Initial thought was like this is pretty simple functionality we have to achieve and will not take more time but unfortunately when we started implementing it we got stuck in iterative problems.
We did tried using the below code which called onSave of the form-
onSave()
{
Xrm.Page.data.entity.save();
setTimeout(function () {
Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
}, 3000);
}
But unfortunately it did not worked, we even tried the same code on the success and failure callbacks of the Xrm.Page.data.entity.save() but there is no luck, most of the time it executed fail callback of the method.
After spending some time on the Google we found the below solution and it worked 100 percent-
First of all we have created a helper function to set or remove listener to internal CRM events:
function addAfterEventHandler(eventId, handler) {
this.parent.Mscrm.TurboForm.Control
.CommandService.get_instance()
.addAfterCommandExecutionHandler(eventId, handler);
}
function removeAfterEventHandler(eventId, handler) {
this.parent.Mscrm.TurboForm.Control
.CommandService.get_instance()
.removeAfterCommandExecutionHandler(eventId, handler);
}
After creating the helper function we have added the listener to the after save event-
addAfterEventHandler(this.parent.Mscrm.InlineCommands.Save, function () {
Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
});
We created the web resource of the above code and loaded the same on the form of entity where we required, that's all whenever you will save the changes for the particular form it will reload the page.
No comments:
Post a Comment