Saturday, January 19, 2013

Dynamics CRM 2011 Open dialog from Javascript

There are many nice things you could do withe dialogs, but making the user to go and choose a dialog from the ribbon isn't really good UI and it doesn't make lot of sense.

Example of when I used the code.
Let say you want to help the user go throw the process of closing case, wouldn't be goo idea to replace the resolve case ribbon button with new ribbon that will open a dialog?

In this example I'm using CrmRestKit, It is required for the code to work, Please make sure you add it to the form.


var DIALOG_NAME = "Test Dialog";

CrmRestKit.ByQuery('Workflow', ['WorkflowId'], "Category/Value eq 1 and StateCode/Value eq 1 and Type/Value eq 1 and Name eq '" + DIALOG_NAME + "'", false)
            .fail(function (t) {
            .done(function (data, status, xhr) {
            // Assert
            //equals(data.d.results.length, 2, 'Expected two');          
            if (data.d.results.length < 1) {
                alert("Missing dialog named: '"+DIALOG_NAME+"'");
            var dialogId = data.d.results[0].WorkflowId;
            var objectId ="{", "%7b").replace("}", "%7d");
            var url = Xrm.Page.context.prependOrgName("/cs/dialog/rundialog.aspx?DialogId=%7b" + dialogId + "%7d&EntityName="+ +"&ObjectId=" + objectId);
            var returnValue = showModalDialog(url);


  1. Or, you could use the "Invoke Process Dialog" action from CRM Rules! (, and not have to write any code..

  2. Hi Yairrose ,

    That's good idea ,thanks for sharing .

    Dynamics CRM Developers