"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Thursday 7 July 2011

How to call a Dialog in CRM 2011 using Javascript

Let's see how to call a Dialog using Javascript in CRM 2011.
Firstly we need to find out the ID of the Dialog. This could be attained in 2 ways.

1. Search with Dialog name in Customizations.xml

For eg: If you search with your dialog name, you could find something similar to this.

<Workflow WorkflowId="{a13ad982-d812-40a0-ab67-f314cdabbd2b}" Name="MyDialog">
</Workflow>


2. Open the Dialog and press F11 to get the URL. In the URL we could find out the ID of the Dialog.


Javascript Code snippet:
var dialogId = "a13ad982-d812-40a0-ab67-f314cdabbd2b"; // This must be your Dialog ID
var returnValue = showModalDialog("/" + Xrm.Page.context.getOrgUniqueName() + "/cs/dialog/rundialog.aspx?DialogId=%7b" + dialogId + "%7d&EntityName=account&ObjectId=" + Xrm.Page.data.entity.getId());

//Optional:To save and close entity form as soon as the dialog is closed.
Xrm.Page.data.entity.save("saveandclose");


Sample Scenario  :
To open a Dialog when the user clicks on Ribbon button of the entity form.



2 comments:

  1. Thank you very much for sharing this information it was really helpful for me.

    As Microsoft have recently changed CRM Online to be linked in with Office 365 I had to make a very minor change to the call of the showModalDialog method to get it working.

    var dialogId = "69095BF7-C20A-48BD-BCB5-989D5742D480";
    var returnValue = showModalDialog("/cs/dialog/rundialog.aspx?DialogId=%7b" + dialogId + "%7d&EntityName=new_request&ObjectId=" + Xrm.Page.data.entity.getId());

    ReplyDelete