I had
a need to refresh crm 2016 form right after initial save. Surprisingly all good
old solution from my archive were not effective in crm 2016. Neither
window.location.reload(), nor sdk’s refresh, nor trivial setTimeout. "setTimeout"
would work if not bunch of heavy plugins and JavaScrippt validation on save
event.
I found that
Google knows about it as many as I do. Okay, no copy past this time J
After half an hour
I found a nice solution with really minimal risk of browser leaking. The idea based
on fact that OnLoad event occurs without form refresh right after change of
form type. We need an independent flag to catch that. The code below does the trick.
function refreshFormAfterInitialSave() {
if (Xrm.Page.ui.getFormType() == 1) {
top.callN = 1;
}
if (Xrm.Page.ui.getFormType() == 2 && top.callN == 1) {
setTimeout(function () {
top.callN = null;
Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
}, 2000);
}
//////////////////////////////////////////
OnLoad: function (context) {
//set id for first call after save
refreshFormAfterInitialSave();
},
It works fine and refreshes the form only once after initial
save. If you hit new on existing form, it will work correctly too for new form an its heirs. I’m not sure I’ve
made all possible tests but hope it saved your time.
Happy coding!
Comments
https://tobiaskoller.blogspot.de/2018/02/dynamics-crm-365-and-earlier-after-save.html
function refreshFormAfterInitialSave() {
if (Xrm.Page.ui.getFormType() == 1) {
top.callN = 1;
}
if (Xrm.Page.ui.getFormType() == 2 && top.callN == 1) {
setTimeout(function () {
top.callN = null;
Xrm.Page.data.refresh();
}, 3500);
}
}