We often launch Dialogs from Ribbon buttons to save a few clicks. But you could fire this code in the OnLoad event too, specifying if you wish to refresh, by setting the function param to "true".
If you were to use this function with a Ribbon button, the action would be a JavaScript Function, and the params would be (in order) String, String, Crm Parameter, Boolean Parameter.
var popup;
var detailsWindowTimer;
function LaunchModalDialog(dialogID, typeName, recordId, refresh) {
var url = window.location.protocol + "//" + window.location.host;
if (window.location.href.indexOf(Xrm.Page.context.getOrgUniqueName()) > 0) {
url = url + "/" + Xrm.Page.context.getOrgUniqueName();
}
url = url + '/cs/dialog/rundialog.aspx';
popup = window.open(url + '?DialogId=' + dialogID + '&EntityName=' + typeName + '&ObjectId=' + recordId, "Dialog", "status=0,toolbar=0,scrollbars=0, resizable=1");
if (refresh != null && refresh == true) {
detailsWindowTimer = setInterval("WatchDetailsWindowForClose()", 600); //Poll
}
}
function WatchDetailsWindowForClose() {
if (!popup || popup.closed) {
/// Do your stuff here....
clearInterval(detailsWindowTimer); //stop the timer
window.location.reload(true);
}
}