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

Wednesday 23 February 2011

How to refer a Web Resource file from Customizations file or Site map in MS Dynamics CRM 2011

Consider a scenario in MS Dynamics CRM 2011 where  you would like to change the icon of Workplace icon on the left navigation pane. In CRM 2011 its possible to upload the new icon file as a resource file into web resources and refer it from the sitemap. A sample is given below. In this code snippet, customIcon is a file which was uploaded to the webresources folder of MS Dynamics CRM 2011 and we are refering it using the simple code $webresource:customIcon 

The key advantage of this approach is that the uploaded webresource is used without depending on a particular server or physical location. As we all know its also possible to refer an icon file from either from a physical location or from a hosted URL. But just imagine what would happen if we move the Solution to another server. Hence the webresource reference approach becomes a valuable one. All supported webresource files could be used in the same way. Syntax is very simple too $webresource:webresourcefilename

Code snippet from Sitemap:


<Area Id="Workplace" ResourceId="Area_Workplace" ShowGroups="true" Icon="$webresource:customIcon" DescriptionResourceId="Workplace_Description">
</Area>


Code snippet from a Customizations.xml:

<CommandDefinitions>
<CommandDefinition Id="Org.CustomEntity.Form.CommandDefinition.TestButton">
<EnableRules>

<EnableRule Id="Org.contact.WebClient.EnableRule" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Org.contact.WebClient.DisplayRule" />
</DisplayRules>
<Actions>
<JavaScriptFunction Library="$webresource:yourjavascriptfile.js" FunctionName="Display">
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>

Another scenario -Consider that we placed a Button on the ribbon XML of an entity form and we would like to execute a javascript file when the end-user clicks the button. As explained above firstly upload the javascript file into Webresources of the solution. And refer the js file using the same syntax as shown above. When you move Solution to another server, you don't need to move the js file separately because its already in webresource and certainly the webresources will be moved along with Solution.

No comments:

Post a Comment