Monday 18 March 2013

Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online - Image (PNG, JPG, GIF, ICO) Web Resources

Web resources are a great step forward and were introduced in Microsoft Dynamics CRM version 2011.

Web resources are a great way to act as a container. Web resource can store a piece of JScript code, image, etc.

Web resources are virtual files which are always stored in the Dynamics CRM 2011 database. This is beneficial as we don't have to worry about the physical files and their locations.

Web resources have a unique path and can be accessed through that URL. This is beneficial as we can use the URL in our code.

There are the following kinds of web resources:
  • JScript
  • XML
  • XSL
  • Image (types are ICO, PNG, JPG, GIF)
  • HTML
  • CSS
  • Data
  • Silverlight

The 3 most widely used types are JScript, HTML and Image. Read my blog for more information on Script (JScript) Web Resources.

In this blog I will show how to create and use an image web resource.

Image web resources are the container for the images in ICO, PNG, JPG or GIF format. Image web resources can be used for:
  • Custom Entity Icons
  • Display images on the Entity Forms
  • Icons for Custom Ribbon Buttons
  • Icons for Site Map
In this blog I will create an Image web resource to store a JPG image. I will include this image on an entity form.

1) I have an entity called "Movies". I have few movie records.

"Movies" Entity and Records
"Movies" Entity and Records

2) In the movie entity record, I want to place an image on top of the form. This image will be the same for every movie entity record. Below I have shown the area where I would be displaying the image.

Movie Record "Pirates of the Caribbean: On Stranger Tides"
Movie Record "Pirates of the Caribbean: On Stranger Tides"
3) I have an image which I would like to display on every form.

Image Displayed on Every Movie Form
Image to be Displayed on Every Movie Form
4) I will create a web resource. I will go to my "Movies" solution.

"Movies" Solution
"Movies" Solution
5) I will go to the "Web Resources" component inside the solution. 

"Web Resource" component inside the Solution
"Web Resources" component inside the Solution "Movies"
6) I will create a new web resource called "Movies Header Image". I have selected the "Type" as "JPG format". This means this web resource is of type image and format is JPG. Click "Save".

Movies Header Image Web Resource
Movies Header Image Web Resource
7) The web resource is created. There is a unique URL created for this web resource. This means the image can be accessed through this web resource URL.

By creating an image web resource, we are making sure that this image is available to Dynamics CRM 2011 for use.

The URL created here is:
http://crm2011:5555/AshishMahajan/WebResources/new_Movies.HeaderImage.

Movies Header Image Web Resource Created
Movies Header Image Web Resource Created
8) Publish this web resource. We need to publish the web resource to make it available. After publishing I can start using the web resource in my "Movies" entity form.

Publish Web Resource
Publish Web Resource
9) I will go to "Movies" entity form and insert this web resource. The "Movies" entity is under the Entities component in the solution.

Movie Entity in the Solution
Movie Entity in the Solution
10) Open the main information form for the "Movies" entity.

Open the Main Information Form for the "Movies" Entity
Open the Main Information Form for the "Movies" Entity
11) Click on the "Insert" tab on the form. Here we have the option to add a "Web Resource". Click on the ribbon button "Web Resource".

Insert Web Resource
Insert Web Resource
12) I have entered the following properties for this web resource. I have selected the image web resource; I created above in the field "Web resource". Click "OK".

Web Resource Properties
Web Resource Properties
13) This will place a control at the end of the section (which is selected).

Web Resource Control Created
Web Resource Control Created
14) Since I want to display this control on the top, so I will drag it to the top of "Movie Name" field.

Go to "Home" tab. Click "Save and Close".

Drag the Web Resource Control to the Top of Movie Name Field
Drag the Web Resource Control to the Top of Movie Name Field
15) Publish changes to the "Movie" entity.

Publish the Movie Entity
Publish the Movie Entity
16) The web resource will be displayed on all the "Movie" entity records. Below, shown, are 3 movie record examples displaying this image.

Movie - Pirates of the Caribbean On Stranger Tides
Movie - Pirates of the Caribbean On Stranger Tides
Movie - Skyfall
Movie - Skyfall
Movie - The World Is Not Enough
Movie - The World Is Not Enough
I have used this blog to create and display an image web resource on an entity form. You can very well display it as a custom ribbon button icon or a site map icon or a custom entity icon.


I hope this blog about 'Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online - Image (PNG, JPG, GIF, ICO) Web Resources' was informative. Please feel free to leave your comments.

Sunday 17 March 2013

Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online - Supported and Un-Supported Code, Customizations and Extensions

Microsoft Dynamics CRM 2011 is a robust application. It is a highly customizable xRM platform which can be used as a non-CRM application.

Dynamics CRM 2011 can be customised and extended in many ways:
  • Customizing Site Map 
  • Changing Icons
  • Customizing Ribbon Buttons
  • JScript Web Resources
  • Other Web Resources (HTML, CSS, XML, Image, Silverlight, etc.)
  • Plugins
  • Workflows
  • Dialogs
  • Custom Workflow Activities
  • SSRS Reports
  • Integration with other applications through tools like Scribe, etc.

When customising and extending Dynamics CRM 2011, always write supported code. Supported code is the code which falls between the boundaries of Dynamics CRM platform. Meaning the code is well integrated into the Dynamics CRM architecture and is easily upgradeable.

On the other hand unsupported code or unsupported customisations fall outside of what should be done in Microsoft Dynamics CRM 2011. It is not that the unsupported code will not work or not produce the desired results. The unsupported code if written correctly will do the job, but is not supported by Microsoft. In simple words Microsoft takes no responsibility for your unsupported code.

The problems with unsupported code or unsupported customizations are:
  • Future service updates or rollups for Dynamics CRM 2011 can reverse your changes. In worst case scenario the installation of the service update or rollup will fail. 
For example, if you change manually any of the core Dynamics CRM files to change the look and feel of CRM. Next time when you try to install the service update or rollup, the installation might overwrite those core files. This will remove your changes and you will have to make those changes again.
  • When you try to upgrade to the next version of Microsoft Dynamics CRM, this could lead to many issues. Upgrade from current to future versions will be seamless if your CRM 2011 has all the supported customisations. In case of unsupported customisations, there could be errors as that piece of code could no longer be executed in CRM's programming model.
  • If you are a large IT consultancy firm and are involved with your customer for their critical enterprise level Dynamics CRM project. This project involves more than a year of development. Before go-live your customer calls another company for final auditing of this project. If those company's consultants pin-point that there are unsupported code and customisations, this could be a major source of embarrassment for your organisation.
  • There is no Microsoft support for unsupported code and unsupported customisations in Dynamics CRM.

Few Examples of Unsupported Customisations

  • Document Object Model (DOM): Referencing Document Object Model (DOM) objects in HTML in JScript is not supported. Always use the new CRM 2011 XRM Page programming model. The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. 

You can read more about JScript development and the cheat sheet in one of my blog.

  • SSRS Reports: SSRS reports in Dynamics CRM 2011 should always be either Fetch XML based or filtered views based. SSRS reports based on SQL which accesses non-filtered views are unsupported.
In Dynamics CRM database there are always 2 types of views "filtered" and "non-filtered". Non-filtered view is named, based, on the entity's name. For example, "select * from account" will get me all records. "account" here is a view which will combine tables like  "AccountExtensionBase", "AccountBase" and other related tables. "account" view is a non-filtered view which never has security inbuilt into its script. On the other hand if I use "select * from FilteredAccount", I will get only the records to which I have access. Use of filtered views is supported over the use of non-filtered views.
  • Direct Database Table Modifications: Direct database table modifications, through code, are unsupported. For example, in a plugin if I have code which changes the status of an entity record through a SQL script, this is unsupported. Always use CRM 2011 web services to make changes to any entity fields.
  • CRM 2011 SDK: The best reference for always writing supported code is the CRM 2011 SDK. 
SDK has articles and examples on how to extend and customise CRM. If it's not there in SDK, then it is likely to be unsupported.
  • Ribbon: You can always extend Ribbon XML and customise by adding you own buttons. Ribbon buttons defined for system entities are already there when CRM 2011 is installed. You can hide or disable them. You can also use CRM 2011 Ribbon commands. Reuse of CRM 2011 Ribbon JavaScript functions is unsupported. Reason being these functions can be overwritten during upgrade or get deprecated.
  • Database Schema Changes: Physical changes to the CRM 2011 database schema are unsupported. This could lead to severe performance issues or even CRM 2011 being unavailable.
The only supported changes are adding new or updating existing indexes.
  • Help Content: Changes to the help content for CRM 2011 application is not supported for on-premises.
  • Core CRM Files: Changes to Core CRM files in its installation directory is unsupported.
  • CRM 2011 IIS Website: Making changes within the CRM 2011 IIS website like adding another website is unsupported.
I hope this blog about 'Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online - Supported and Un-Supported Code, Customizations and Extensions' was informative. Please feel free to leave your comments.

Thursday 14 March 2013

Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online - Get the Form Control ID

Microsoft Dynamics CRM 2011 is a web application. It is setup as a web application in IIS. It can be browsed through the clients such as a web browser or Microsoft Outlook. Previously Dynamics CRM could only be accessed through a single web browser Internet Explorer. The latest release of Microsoft Dynamics CRM called Update Rollup (UR) 12 delivered multi-browser support. The Dynamics CRM 2011 access in Microsoft Outlook is also through Internet Explorer. If you open the records in Microsoft Outlook, they actually open in the Internet Explorer browser window.

In this blog I will show how to get the ID of any Microsoft Dynamics CRM 2011 form controls in Internet Explorer.

There are many occasions where one would need the ID of a control on a Dynamics CRM 2011 form. Like in my case I want to change the images on the form based on the record selected. I have an entity called "Movies". For every movie record there is a "JPG" web resource storing the movie poster image. I want to dynamically display the related image for a movie record.

"Movie" Entity Records
Below are the 3 "Movie" records and the dynamically displayed images (related to the movie).

"Movie" Record Skyfall

"Movie" Record Casino Royale

"Movie" Record GoldenEye
The image, on a CRM 2011 form, is displayed as an inserted web resource control.

"Movies" Entity Form Design Showing the Web Resource Control
This web resource displays an image by default. The same image will be displayed for all movies. In order to dynamically change this image I need to write a JScript web resource. The JScript code displays the image web resource and is dynamically selected based on the "Movie" record name.

JScript Code
As seen above the web resource is selected based on the movie record name. There is an Image Web Resource for every movie and is named after the record name. In Jscript to code the display of the Image Web Resource in the image control, I need the ID of this image control. In the JScript code, above, the ID used is "WebResource_Movie_Images".

I can find the ID of any Microsoft Dynamics CRM 2011 control from the Internet Explorer "F12 Developer Tools". Internet Explorer Developer Tools (formerly known as Internet Explorer Developer Toolbar), is a component of Internet Explorer that aids in design and debugging of web pages. 

Open any "Movie" form. Let's say I have opened the "Movies" entity record GoldenEye. Press F12 on the keyboard to open the tools. Or else select the "F12 Developer Tools" option from the Internet Explorer right hand side "Tools" menu.

Internet Explorer "Tools" Menu
The Internet Explorer window, below, will now display the "F12 Developer Tools".

Internet Explorer Window Displaying the F12 Developer Tools
I want to find out the ID for the image control. Click the arrow button "Select Element By Click".

Select Element By Click
Select the element (control) on the form whose ID you want. In this case I want the ID of the Image so that I can use that in JScript code. Take the mouse cursor on the image and click once. This will open the HTML for the page on left hand side. On right hand side it displays the CSS for the page. The HTML tag for the image is selected and highlighted in blue.

Select The Image Element (Control)
From this highlighted HTML tag (of Image) in blue, we can get the ID. As seen below, the ID is "WebResource_Movie_Images". This is the same ID which is used in the JScript above.

Selected Image HTML Tag and The ID

In this way we can use the Internet Explorer "F12 Developer Tools". Using this tool we can find out the ID of the Dynamics CRM 2011 form controls. These ID can be used in the JScript as I have done above.

A piece of advice: Before using the control and the ID in JScript code, always check whether the code is supported or unsupported. Unsupported code is the one which doesn't conform to the CRM 2011 platform coding principles. If you write unsupported code, there could be problems in installing future service packs or upgrading to the new Dynamics CRM release.

I hope this blog about 'Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online - Get the Form Control ID' was informative. Please feel free to leave your comments.