Run Dialog in CRM 2015 Easily from JavaScript Library

Paul Nieuwelaar, 12 August 2015

A common requirement is to open a dialog process from JavaScript on click of a command bar button etc. This is quite easy to do, simply using window.open and passing in the right parameters to get the dialog working with the right record.

The problem is that this doesn’t allow us to run code when the dialog closes. We could use modal dialogs, but these are not supported in Chrome. Instead what I’ve done is created a manageable function for running a dialog, which allows us to run code when the dialog is closed.

To download the JavaScript library, check out the project on CodePlex: https://processjs.codeplex.com/

It works by popping the dialog in a CRM light-box, which makes it look natural and seamless. When the dialog is closed, a callback function which we specify can be executed.
image

If the code runs inside outlook, where CRM light-boxes are not supported, a modal dialog is instead used, which still allows us to run our callback function when the dialog closes.

Call Dialog

This function opens the specified dialog for a particular record in a CRM light-box, or Modal Dialog if running from Outlook. Once the dialog is closed, the form or view is refreshed to display any new data changed by the dialog.

Parameters: Dialog ID/Guid, Entity Name, Record ID/Guid, CRM Base URL (not required on forms/views)

Process.callDialog("C50B3473-F346-429F-8AC7-17CCB1CA45BC", "contact", Xrm.Page.data.entity.getId(), function () { Xrm.Page.data.refresh(); });

To download the JavaScript library, check out the project on CodePlex: https://processjs.codeplex.com/