Reputation: 671
I have a Parent entity "A" and child entity "B". I have a subgrid on the parent form to create children. When a child is created and saved, I want the Parent form to reload. I have tried the following in javascript but it doesn't seem to work:
function ReloadParentWindow() {
var loc = window.opener.location;
window.opener.location = loc;
window.opener.location.reload();
window.parent.loacation.reload();
window.parent.opener.location.reload();
window.location.assign(window.location.href);
parent.location.reload();
window.top.location.reload();
}
ALSO tried the following:
function onLoad() {
setTimeout("refresh();", 2500);
}
function refresh() {
alert"A");
Xrm.Page.getControl("clients").addOnLoad(GridOnloadFunction);
}
var GridOnloadFunction = function () {
alert("B");
// Xrm.Page.data.refresh(true);
var Id = Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm("esi_timelog", Id);
window.location.reload(true);
};
I am using CRM 2016 online, google chrome. Please help.
Upvotes: 2
Views: 1846
Reputation: 525
Try this:
var recordcount = null;
function onLoad() {
CheckRecordCount();
}
function CheckRecordCount() {
try {
setInterval(function () {
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("myGrid") != null &&
Xrm.Page.getControl("myGrid") != undefined) {
var rowcount = Xrm.Page.getControl("myGrid").getGrid().getTotalRecordCount();
if (recordcount == null) {
recordcount = rowcount;
} else if (recordcount != rowcount)
Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
}
}, 5000);
} catch (ex) {
Xrm.Utility.alertDialog(functionName + "Error: " + (ex.message || ex.description));
}
}
Upvotes: 0
Reputation: 755
Add an event on the load of the grid in the onload of the parent form. The on load is triggered every time you add a record using the + button:
Xrm.Page.getControl('yourgrid').addOnLoad(onLoadGrd);
Then in the function, you can call a refresh of the parent form:
function onLoadGrd()
{
Xrm.Page.data.refresh()
}
This is the supported way.
Upvotes: 0