Custom Open a Dialog Process in Dynamics 365

By | October 14, 2017
QualTech Custom Development for Dynamics 365 | QualTech360Dynamics

How to run a Dynamics 365 dialog process using a custom javascript

The subject for this article comes from the requirements of one of our customers.

They use Cases in Dynamics 365 heavily. They have a support center handling the cases and wanted to collect some additional data on the closing of each case in order to do some statistic reporting and quality of service provided.

QualTech Dynamics 365 Custom Development | QualTech360Development

Default Resolve Case button and dialog.

The case functionality in crm comes with it’s own case resolving button. When you click the Resolve Case button crm displays a default dialog to confirm the closing as you can see in the picture to the right.

Based on our requirements these are the steps we had to implement:

  1. Hide the out of the box Resolve Case button so the default dialog doesn’t display.
  2. Add a custom Close Case button.
  3. Create the custom dialog process which walks the user through the custom steps.
  4. Create a script that launches the custom close dialog.

In this article I’m just showing you how to write the script that launches the custom dialog process when the user clicks the custom Close Case button. I’m going to assume that you know how to implement the steps 1 through 3.

Below is the javascript needed to load the dialog process.

function CloseCase(dialogId,typeName,recordId )

var openWindow;
var serverUri = Mscrm.CrmUri.create(‘/cs/dialog/rundialog.aspx’);

openWindow = + ‘?DialogId=’ + dialogId + ‘&EntityName=’ + typeName + ‘&ObjectId=’ + recordId, null, ‘width=615,height=480,resizable=no,status=no,scrollbars=no,modal=yes’);

openWindow.onload = function () {

openWindow.onunload = function () {



function UnloadCallback() {



When you call the function to open the dialog 3 parameters must be passed. The dialogId which is the unique id of the dialog process you created. You should find the id in the form you opened to create the dialog.

The crm functionality used to open the dialog is the Mscrm.CrmUri.create(‘/cs/dialog/rundialog.aspx’). This function needs the 3 parameters we pass to the function CloseCase.

QualTech Custom Development for Dynamics 365 | QualTech360DynamicsThe next line highlighted in blue shows the function of the browser object that you are familiar with which allows you to open a new page with javascript. This function loads the rundialog.aspx page with the 3 parameters we passed. You can see what it looks like in the picture to the left.

The next line I have highlighted is the openWindow.onload. This might look a bit complicated but it’s quite simple to understand what this code is doing. All I’m doing here is using the handle to the dialog window that loaded to insert code in the load event. The code inserted adds an anonymous javascript function to the unload event of the opened dialog.

With this code, when the dialog is closed the unload event will call the function UnloadCallback. In this function I force the case form to reload so I can actually see the changes made by the dialog.

This is a fairly simple setup but it allows you to provide crm users with custom dialogs which guide them through custom tasks and you can use the dialogs to perform necessary updates to the crm records without having to create a lot of custom scripts.

As always I hope this might be useful to someone out there.

If you have any questions you can leave a comment or email us at

#QualTech360Care #QualTech360Devlopment #QualTech360DotNet #QualTech360Dynamics

Leave a Reply