Sunday, 29 April 2012

Microsoft Dynamics CRM 2011 - Develop Fetch XML Based SSRS Reports In Visual Studio 2008


Microsoft Dynamics CRM 2011 supports two kinds of custom SSRS reports. One is the old way, using filtered views. Other is the new way, using Fetch XML. The previous version, Microsoft Dynamics CRM 4.0 only supported reports based on filtered views. These filtered views were directly accessed writing TSQL.


Microsoft Dynamics CRM 2011 Online has few differences from its on-premises cousin. One of the differences is we cannot have filtered views based SSRS reports. Microsoft Dynamics CRM 2011 Online only supports Fetch XML based SSRS reports. The reason being you don't have direct access to SQL Server on CRM 2011 Online. This is totally opposite to the on-premises version where you have total control and visibility over your CRM databases. So CRM 2011 on-premises support both filtered views and Fetch XML based SSRS reports, but CRM 2011 Online supports only Fetch based SSRS reports.

Fetch is a proprietary query language that is used in Microsoft Dynamics CRM. It is based on a schema that describes the capabilities of the language. The Fetch XML language supports similar query capabilities as query expression.

The Fetch XML based reports are created the same way, using SQL Server 2008 R2 BIDS (Business Intelligence Development Studio) or Visual Studio 2008. BIDS is an IDE (integrated development environment) having only SSRS report templates, whereas Visual Studio 2008 has all the project templates including SSRS project templates. You also need an additional component for creating Fetch XML based SSRS reports. Microsoft Dynamics CRM 2011 Report Authoring Extension is required to author custom Fetch-based reports for Microsoft Dynamics CRM by using Business Intelligence Development Studio.

Download this component from: Microsoft Dynamics CRM 2011 Report Authoring Extension

In this blog I will create a simple Fetch XML based SSRS report in Visual Studio 2008. I am assuming you know how to upload the report file (*.rdl) into CRM 2011 and run the report in CRM.

1) I will develop a report on two custom entities. One custom entity is Movie and the other is Genre. The report will output the list of movies based on the genre selection. Genre records will be listed as a pick list (option set) report parameter.


The movies will be shown which belong to the selected Genre in the pick list report parameter.


Shown below is the screen shot of movie records in CRM.

Movie Records

2) Below is the screen shot for genre records. The genre is to categorise movies. For example a movie can belong to a 'Family' genre or 'Thriller' genre, based on the story and content. Movies have N:1 relationship with Genres.

Genre Records

3) I will use Visual Studio 2008, to create a SSRS reports solution. I will then create a fetch based report in this solution.

Visual Studio 2008

4) In Visual Studio, click on File > New > Project. This will open a new project window.

Create a New Project

5) In the new project window, go to section "Business Intelligence Projects". Select the project type as "Report Server Project". This SSRS project type will create a blank solution. I can then add a new report with data sources, datasets and queries.

Report Server Project






6) After the project is created add the first item, a Report. Click on Reports > Add > New Item. This will open an "Add New Item" window.

Add a New Report

7) In the "Add New Item" window, select a file of type Report. I will give this report a name "Movies by Genre".

This option will create an empty report file with the extension of rdl (report definition language). 

Selecting a type of Report

8) In the screenshot below, you can see the report "Movies by Genre.rdl" has been created.

Movies by Genre Report

9)  In the report, I will add a data source. This is a connection to my SQL Server CRM database.

Click on Data Sources > Add Data Source. This will open a "Data Source Properties" window. 

Add a Data Source

10) Shown below is the "Data Source Properties" window. Give a name and define a connection to the SQL Server CRM database.

I have named my data source as "SQLConnection". In the embedded connection, select the type as "Microsoft Dynamics CRM Fetch".

In the connection string, I cannot specify a direct connection to my SQL Server CRM database. I have to specify the CRM Organization for which this report will be running. Click OK and a data source is created by the name "SQLConnection".

Data Source Properties

11) I will create a dataset for Genres. Since it is a Fetch XML based report, the query to get genres will be a Fetch XML. It cannot be a TSQL using filtered views.

As I mentioned above, I will have Genre records as a pick list report parameter. Based on the Genre selection, the movie records belonging to that Genre will be shown.

For my blog I will simply download the Fetch XML created automatically by advanced find. In that way I can also show you how to get Fetch XML from advanced find. You don't have to create Fetch XML from scratch. You can have Fetch XML automatically created from advanced find, and then modify if needed as per your needs.

I will go my CRM interface in Microsoft Internet Explorer. I will go to Genres records. I will click "Advanced Find" ribbon button on top right corner. This will open the Advanced Find window.

Fetch XML for Genre

 12) In the Advanced Find window by default there is a condition of status equals active. We can add more conditions. For my report this condition is enough. I will click Download Fetch XML ribbon button on the top right corner.

Download Fetch XML for Genre

13) This will give me an option to either open or save the file. I will select Save As, to save this file on my desktop. I will save this file with the name "GenreFetchXML.xml".

"Save As" Fetch XML for Genre

14) I will go to my desktop and open the file "GenreFetchXML.xml" in notepad.

Fetch XML File for Genre
  
15) As we can see the Fetch XML is there and ready to be used. If we need to modify the query, we can simply do it in notepad or use any text-based editor.

I want the Genre query to retrieve only Name and the GUID, so that I can create a report parameter with a pick list of all Genres. The Fetch XML has 2 additional fields "createdon" and "createdby".  I will remove these 2 fields.

Just on the side note, as seen in the Fetch XML, the field names are logical names and not schema names. Logical names are equal to schema names, but always in lowercase. For more information on logical names and schema names please read my blog:
http://ashishmahajancrm.wordpress.com/2012/03/15/microsoft-dynamics-crm-2011-entity-logical-name-and-entity-schema-name

Fetch XML File for Genre, in Notepad

After removing "createdon" and "createdby", the final Fetch XML is shown as below. I will copy this Fetch XML and paste it in the Genre data set, which I am creating next.

Final Genre Fetch XML

16) I will go to my reports project in visual studio. I will select Datasets and right click. I will select "Add Dataset" to create a new dataset.


Add a New Dataset for Genres

17) This will open a "Dataset Properties" window. I will name my Genre dataset as "GetGenres". I will select option of embedded dataset. I will select the data source as "SQLConnection".

I will paste the copied Genre Fetch XML in the query field. This query is of type Text. Select OK to create this dataset.

Dataset Properties for Genres

18) As seen below the Genres dataset is created with the name "GetGenres".

GetGenres Dataset

19) Now I will create a report parameter, based on the Genres dataset. Select Parameters and right click to add a new parameter.

Add a Parameter for Genre

20) This will open a "Report Parameter Properties" window. I will name the parameter as "Genre". I will give the prompt as "Select Genre". The data type is text.

Genre Report Parameter Properties - General


21) In the "Available Values", select the option "Get values from a query". We will define the source of this report parameter, which in my case is the Genres dataset. I will put "GetGenres" in dataset. The report parameter value will be the genre GUID and the label will be the genre name.

Genre Report Parameter Properties - Available Values


22) In the "Default Values" select the option of "No default value". I don't want the report to have any pre-selected default genre. Click OK to save the report parameter.

Genre Report Parameter Properties - Default Values

23) As seen below a report parameter by the name "Genre" is created.

Genre Parameter Created


24) I will create my second dataset which is for Movies. This dataset will feed the display for the report. Again I will take the same approach of creating a Fetch XML for movies through advanced find.

I will go to my CRM Movies records. I will click on Advanced Find ribbon button on top right.

Fetch XML for Movie

25) This will open the Advanced Find window. I will remove the non-required fields. This I can achieve by clicking on "Edit Columns".

Edit Columns for Movie Fetch XML

26) This will open the "Edit Columns" window. I will remove the last three columns "Number in Series", "Created On" and "Created By", as I don't need them. Select each one of the three columns and click "Remove" button. Click OK.

Remove non-required Columns for Movie Fetch XML

27) After I have removed the non-required columns, I will download the Fetch XML. I will click "Download Fetch XML" ribbon button on top right.

Download Movie Fetch XML

28) This will give me an option to either open or save the file. I will select Save As, to save this file on my desktop. I will save this file with the name "MovieFetchXML.xml".

"Save As" Fetch XML for Movie


29) I will go to my desktop and open the file "MovieFetchXML.xml" in notepad.

Movie Fetch XML File

30) As you can see the Movie Fetch XML has the columns which I selected. I will copy this Movie Fetch XML and use it in the Movie dataset.

Movie Fetch XML in Notepad

31) Go to Datasets and right click to add a new Dataset.

Add a New Dataset for Movies

32) This will open a "Dataset Properties" window. This is the same way we created Genre dataset. I will name the new dataset as "GetMovies". I will select the data source as "SQLConnection". In Query I will paste the Movie Fetch XML, which I had copied earlier. Click OK.

Dataset Properties for Movies

33) As seen below, "GetMovies" dataset is created.

GetGenres and GetMovies

34) I will add a table to my report. This table is a layout where my movie records will be displayed.

I will click Toolbox, on the left side, to expand it. I will select a table, drag and drop on to the report's designer.

Add a Table

35) As seen below a table is created. The table has 2 rows (header and data) and 3 columns by default. I can add or delete data rows and columns.

Table

36) I will add the dataset "GetMovies" to the "DataSetName" property of the table. This will bind the "GetMovies" dataset to the table so that the data rows can display the records from FetchXML.

Select a DataSet for the Table

37) I will finalise designing my table. For simplicity, I will display only two columns, the Movie GUID and the Movie Name. I have removed the third column. I have formatted the table header with a yellow background and aligned header to the center.

In the table data row, for first column I will click on upper right corner and select new_movieid. I will do the same for second column (as shown below) and select new_name. These field options appear automatically as I have already set the DataSetName property of the table equal to "GetMovies" dataset.

I have completed designing my report. I can go ahead and test it.

Configure Table for Display
 
38) Select the Preview tab in Visual Studio. This tab is used to run a SSRS report created in Visual Studio. We should always test the report before we upload it to CRM. This way we can remove any issues before uploading the report to CRM.

In the preview tab, as shown below, I can see a parameter labelled "Select Genre". The parameter lists all the Genres. I will select Family genre and click "View Report" button.

Testing the Report


39) As seen below the report has produced output. It shows all the movies whose genre is family.

You can format your Fetch XML based report as per your requirements. You can upload this Fetch XML based report the usual way into your CRM 2011 environment.

Report Output

In this blog we saw how easy it is to design a Fetch XML based SSRS report in Visual Studio 2008. You can create a report on a simple Fetch XML as I did above or you can use as complex Fetch XML as you like.

Remember, there is a Download Fetch XML button provided so that we can have ready-made queries. Microsoft has done a great job in giving us this option of downloading Fetch XML and saving us a lot of time.

I hope this blog about 'Microsoft Dynamics CRM 2011 - Develop Fetch XML Based SSRS Reports In Visual Studio 2008' was informative. Please feel free to leave your comments.

Tuesday, 17 April 2012

Ribbon Interface Deja Vu; an Awesome step forward for the future of Microsoft's Software Product Usability

Ribbon interface will be an awesome step forward for the future of Microsoft's software product usability.
The way I look at it, ribbon buttons give the same look and feel across all the recent products released by Microsoft. The products are SharePoint, MS Office, Dynamics CRM 2011, Microsoft Office 365, etc. to name few. So the users and developers who are using these Microsoft products feel connected when they move from one application to another. They feel a sense of Deja Vu, if I must say.

The best thing is Microsoft has already started putting all its business software online and in the cloud. Take Office 365, Dynamics CRM 2011 online, Office Documents, etc. All these online versions have one thing in common. A friendly and common way to access the menu functionality in the form of Ribbon interface.

Even our good old friend "Windows Explorer" in Windows 8 and Windows Server 8 has Ribbon Interface. 
Another good example of how Ribbon Interface has made our lives easier. Shifting between online and local versions is much more seamless. I have stopped using notepad and use Microsoft One Note online. Ninety-nine % of the time I have internet connectivity, so I use my MS One Note online through my SkyDrive. Rest 1% when I don't have internet connectivity, I use my local One Note software, which is installed on my desktop. I sync my notes whenever needed. Since the online One Note has the same ribbon interface as the local version, so my work is seamless and I exactly know which options are under which tab. 
I will show some screenshots across few Microsoft products, highlighting the common look and feel of Ribbon Buttons.

1) Microsoft Dynamics CRM 2011

Below is the Ribbon Interface for Microsoft Dynamics CRM 2011. This ribbon interface is shown when I am on a particular entity screen. The best thing about Ribbon Interface is the flexibility of changing buttons depending on which screen I am on.

Ribbon Interface in Microsoft Dynamics CRM 2011

See how the ribbon buttons have changed, if I open any record. This is to reflect the changes in the options according to what I am supposed to achieve on my current screen. Below are the ribbon buttons of a CRM 2011 Movie entity record.

Ribbon Interface in Microsoft Dynamics CRM 2011 Movie Entity Record

2) Microsoft Office 365

Microsoft Office 365 is a collection of business productivity software. It is secure, anywhere access to email and calendars, Office Web Apps, web conferencing, and file sharing. Below is a screenshot showing the common look and feel of the Ribbon Interface.

Ribbon Interface in Microsoft Office 365

3) Microsoft SharePoint 2010

Below is the Ribbon Interface on my personal SharePoint 2010 site.

Ribbon Interface in Microsoft SharePoint 2010 Site

The same Ribbon Interface is on top of SharePoint Administration site.

Ribbon Interface in Microsoft SharePoint 2010 Administration

4) Microsoft Office One Note 2010

Microsoft One Note has come up in a very big way to revolutionize how we keep our notes up to date. Microsoft One Note 2010 is in cloud and can be accessed 24/7 from anywhere, from your SkyDrive.

Below is the Ribbon Interface for Microsoft One Note 2010 online. Shown below is my One Note on my SkyDrive.

Ribbon Interface in Microsoft Office One Note 2010 (Online Version)
Below is the same ribbon interface on my local copy of One Note. It is so easy for me to shift between the online and the offline versions. It is a total seamless experience. Same is the case for other Microsoft Office documents which are available online (on Cloud).

Ribbon Interface in Microsoft Office One Note 2010 (Desktop Software)
5) Windows Explorer (Windows 8 Operating System)

Windows Explorer in the new upcoming Windows 8 operating system has a new look and feel in the menu area. The menu has been replaced with the Ribbon Interface. This is quite handy.

 For more information on Windows 8 and Metro style (tiled) interface please read my blog: http://ashishmahajancrm.blogspot.com.au/2012/03/first-look-at-screenshots-and-whats-new.html

If I select a folder, the ribbon buttons change and give me the options of the events I can perform on my folders. If I select a file, the ribbon buttons now change and give me the options of the events I can perform on my files.

Ribbon Interface in Windows Explorer (Windows 8 Operating System)

6) Microsoft Office 2010

Below is the Ribbon Interface for all the remaining Microsoft Office products.

Ribbon Interface in Microsoft Office 2010 - Outlook 2010
Ribbon Interface in Microsoft Office 2010 - Access 2010










Ribbon Interface in Microsoft Office 2010 - Excel 2010
Ribbon Interface in Microsoft Office 2010 - PowerPoint 2010
Ribbon Interface in Microsoft Office 2010 - Project 2010
Ribbon Interface in Microsoft Office 2010 - Visio 2010
Ribbon Interface in Microsoft Office 2010 - Word 2010

So you can see how Ribbon Interface has merged the unique UI experience which was previously staggered and unique to each product.

The experience is totally cool and seamless!

I hope this blog about 'Ribbon Interface Deja Vu; an Awesome step forward for the future of Microsoft's Software Product Usability' was informative. Please feel free to leave your comments.