web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / CRM Fields / Refresh CRM 2016 Form after...

Refresh CRM 2016 Form after record save using JavaScript

Micchael Profile Picture Micchael 390

    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!

This was originally posted here.

Comments

*This post is locked for comments