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.

Javascript:


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) {
            alert(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+"'");
                return;
            }
            var dialogId = data.d.results[0].WorkflowId;
            var objectId = Xrm.Page.data.entity.getId().replace("{", "%7b").replace("}", "%7d");
            var url = Xrm.Page.context.prependOrgName("/cs/dialog/rundialog.aspx?DialogId=%7b" + dialogId + "%7d&EntityName="+ Xrm.Page.data.entity.getEntityName() +"&ObjectId=" + objectId);
            var returnValue = showModalDialog(url);
        });

3 comments:

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

    ReplyDelete
    Replies
    1. But that would cost some money, would it?

      Delete
  2. Hi Yairrose ,


    That's good idea ,thanks for sharing .



    Dynamics CRM Developers

    ReplyDelete