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

Sunday 17 July 2011

How to refer a webresource file from Javascript in CRM 2011

As we all know,  webresources utility is one of the very good features of CRM 2011.
Let's see how to refer a webresource from Javascript file in CRM 2011.

Its very simple syntax. For Instance,
Imagine that you have uploaded a webresource called new_ConfigureAttributes.xml
If you want to refer it in Javascript at some point, you could use the following syntax

var xmlPath = "../WebResources/new_ConfigureAttributes.xml";

For a detailed sample, you could have look at the following post.

Related Post :Reading an XML file in CRM 2011 using javascript http://crmdm.blogspot.com/2011/02/reading-xml-file-in-ms-dynamics-crm.html

The key advantage is that its not dependent on any folder structure and also its easy to refer it. You have a file ( could be any web resource file eg:xml, jpg,css,png etc) and you need to upload it to webresources first and then refer it from Javascript whenever required. Even if you move solution from one environment to another it would work perfectly. The reason is simple, its a direct reference to Webresources which is a part of solution. If you want to refer a webresource from Sitemap or Customizations.xml , you could refer the following post.

How to refer a webresource file from Sitemap or Customizations.xml
http://crmdm.blogspot.com/2011/02/how-to-refer-webresource-file-from.html

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.