You are on page 1of 48

REPORTING INTEGRATION L AB WITH SUGARCRM COMMUNITY EDITION AND MICROSOFT SQL SERVER 2008 REPORTING SERVICES

Published: April 2010

Abstract
This lab uses a basic sample to demonstrate how to use Microsoft SQL Server Reporting Services to add reporting features to the SugarCRM Community Edition application. The lab covers the initial steps to achieve such integration leveraging the SQL Server Reporting Services Software Development Kit (SDK) for PHP. Note that this lab is for educational purpose about the potential possibilities and does not demonstrate a final solution that is ready for production use.

Table of Contents

Introduction.................................................................................................................................................. 3 Lab Overview .............................................................................................................................................. 4 Lab Products and Solutions ...................................................................................................................... 5 SugarCRM Community Edition ............................................................................................................. 5 Microsoft SQL Server Reporting Services (SRSS)............................................................................ 5 SQL Server Reporting Services SDK for PHP ................................................................................... 6 Lab Execution ............................................................................................................................................. 7 Step 1: Designing Reports for SugarCRM Community Edition ....................................................... 8 Getting Ready ...................................................................................................................................... 8 Creating a Linked Server against MySQL SugarCRM Database ................................................ 9 Deploying a Sample SugarCRM Report Solution......................................................................... 17 Viewing the Deployed SugarCRM Reports in Report Viewer ..................................................... 19 Step 2: Installing SQL Services Reporting Module in SugarCRM................................................. 21 Adding the Reports Module in SugarCRM .................................................................................... 21 Step 3: End User Experiences ............................................................................................................ 27 Creating a New Report in Report Designer ................................................................................... 27 Viewing the New Report in Reports Viewer .................................................................................. 43 Viewing the New Report in SugarCRM .......................................................................................... 44 The Interop Vendor Alliance ................................................................................................................... 47

Introduction
There are many web applications built with PHP that need to include Business Intelligence and Reporting features. Such features can be built from scratch or leverage external components providing out of the box features. This lab uses a basic sample to demonstrate how to use Microsoft SQL Server Reporting Services to add reporting features to existing PHP applications. The lab covers the initial steps to achieve such integration leveraging the SQL Server Reporting Services Software Development Kit (SDK) for PHP. In this particular scenario, this lab uses the popular SugarCRM Community Edition, a web based Customer Relationship Management system, to demonstrate how to combine SQL Server Reporting Services with third party software. These scenarios teach how to build additional reporting capabilities inside the SurgarCRM Community Edition while offering the end-users more business intelligence tools right inside the SugarCRM Community Edition dashboard.

Note that this lab is for educational purpose about the potential possibilities and does not demonstrate a final solution that is ready for production use.

Lab Overview
This lab demonstrates how to use Microsoft SQL Server Reporting Services (SSRS) to add reporting features to the SugarCRM Community Edition and explains the initial steps to achieve such integration. The lab explores major steps on how to use the SQL Server Reporting Services Software Development Kit (SDK) for PHP to generate and display reports in PHP applications like SugarCRM Community Edition. The use case scenario implemented in the lab is the following: Step 1: The user logs-on to the SugarCRM application and navigates to the report module dashboard. Step 2: The SugarCRM module calls the corresponding SSRS SDK for PHP API to load and render the report from the report server. Step 3 and 4: The Reporting Service connects to the SugarCRM database through SQL Server Express using the configured Linked Server and runs the report. Step 5: The Reporting Server returns the processed report in the desired format. Step 6: The SugarCRM module displays the report.

Heres an overview of the architecture of the solution:

The key benefits of using SSRS SDK for PHP are: The SDK offers a simple interoperability bridge between PHP and Microsoft SQL Server Reporting Services The SDK is independent of the host operating system. The SDK allows developers to control and display reports in any PHP application.

Lab Products and Solutions


SugarCRM Community Edition
SugarCRM Community Edition is an open source and web based Customer Relationship Management (CRM) tool that helps organizations keep track of and manage customer relationships. SugarCRM helps manage various aspects of information on customer relationships such as customer accounts, sales leads, and activities related to customers. The core modules of SugarCRM are: Sales Management Marketing Automation Collaboration News Service Administration

The open source architecture of SugarCRM allows other software vendors to build various enhancements and modules and then integrate them with SugarCRM. SugarCRM also offers Professional and Enterprise editions. More information at: http://www.sugarcrm.com

Microsoft SQL Server Reporting Services (SRSS)


Microsoft SQL Server 2008 Reporting Services provides a complete, server-based platform designed to support a wide variety of reporting needs enabling organizations to deliver relevant information where needed across the entire enterprise. More information at: http://www.microsoft.com/sqlserver/2008/en/us/reporting.aspx The scenarios described in this lab can be done using the free SQL Server 2008 Express with Advanced Services edition that includes Reporting Services. More information on SQL Server Express: http://msdn.microsoft.com/en-us/library/ms365248.aspx

SQL Server Reporting Services SDK for PHP


This SDK offers a simple Application Programming Interface (API) to interoperate with SQL Server Reporting Services. The API provides simple methods to perform the most common operations: list available reports within a PHP applications, provide custom parameters from a PHP web form, manage the rendering of the reports within a PHP application.

The API is built on top of the SQL Server Reporting Services Web Service API using SOAP as the underlying communication mechanism. PHP applications can then manage reports, parameters, credentials, and output formats with SQL Server 2008 Reporting Services. The design of the report is created with Business Intelligence Development Studio which comes with SQL Server 2008 Express with Advanced Services. Developers can alter the style of the output formats to fit their needs. The following code snippet shows how to use SSRS SDK for PHP APIs to connect to report server, load a report, and run and display the report.
/* connect to the Report Service */ $rs = new SSRSReport(new Credentials(UID, PASWD),REPORT_SERVICE_URL); /* Load a report */ $executionInfo = $rs->LoadReport2(REPORT, NULL); /* Define the report parameters */ $parameters = array(); $parameters[0] = new ParameterValue(); $parameters[0]->Name = "ProductCategory"; $parameters[0]->Value = "1"; $parameters[1] = new ParameterValue(); $parameters[1]->Name = "StartDate"; $parameters[1]->Value = "1/1/2003"; /* Set the report parameters */ $rs->SetExecutionParameters2($parameters); /* Define the expected report format as HTML */ $renderAsHTML = new RenderAsHTML(); /* Run and get the report in html format */ $result_html = $rs->Render2($renderAsHTML, PageCountModeEnum::$Actual, $Extension, $MimeType, $Encoding, $Warnings, $StreamIds); /* Display the report */ echo $result_html;

More information on the SDK is available the on Interoperability Bridges website: http://www.interoperabilitybridges.com/projects/sql-server-reporting-services-sdk-for-php

Lab Execution
The use case scenario implemented in the lab is the following: Step 1: The user logs-on to the SugarCRM application and navigates to the report module dashboard. Step 2: The SugarCRM module calls the corresponding SSRS SDK for PHP API to load and render the report from the report server. Step 3 and 4: The Reporting Service connects to the SugarCRM database through SQL Server Express using the configured Linked Server and runs the report. Step 5: The Reporting Server returns the processed report in the desired format. Step 6: The SugarCRM module displays the report.

Heres the detailed architecture of the solution deployed during this lab:

The following sections explain how to configure the different pieces of software in order to have them to work together. The lab execution includes three steps: Step 1: Designing Reports for SugarCRM Step 2: Installing SQL Services Reporting Module in SugarCRM Step 3: End User Experiences

Step 1: Designing Reports for SugarCRM Community Edition


Getting Ready
This lab scenario shows how to deploy a simple reporting solution that defines a set of reports and uses SugarCRM as the data source. This solution uses a Linked Server to connect to the MySQL SugarCRM data source. The sample described in this lab is available for download on the Codeplex SSRS SDK project site: http://ssrsphp.codeplex.com. It includes scripts and additional documentation (direct link: http://ssrsphp.codeplex.com/releases/view/43500 ). Note that this lab is for educational purpose about the potential possibilities and does not demonstrate a final solution that is ready for production use: We didn't enforce authorization rules for the SSRS reports, this means that all users will be able to run the reports If user access needs to be enforced, the index.php file used for the SugarCRM module needs to be extended to add the access rules based on the SugarCRM user currently connected to the dashboard.

The Report Designer is hosted within the Microsoft Visual Studio environment and is used to design the report. The report designer provides a collection of design and graphical query tools that are used to design the report. The Report Designer used SQL Server Express Linked Server to connect to the SugarCRM MySQL database. This lab scenario assumes the following: SugarCRM is installed. SugarCRM database is setup with the test data if required. SQL Express 2008 with Advanced Services is installed. SQL Server Reporting Services (included in SQL Express 2008 with Advanced Services) is installed. Microsoft BI Studio Report Designer is installed (Report Designer is hosted in the Business
Intelligence Development Studio, which is fully integrated with the Microsoft Visual Studio 2008 development environment. If you do not have Visual Studio 2008 installed, SQL Server Setup installs the shell so that you can run Report Designer)

Linked Server is configured on the local SQL Server Express instance against MySQL SugarCRM database.

The configuration of the Linked Server consists of the following steps: 1. Installing MySQL ODBC Driver. 2. Configuring MySQL DSN. 3. Configuring Microsoft OLEDB Provider for ODBC Drivers (MSDASQL) to use the MySQL Connector/ODBC DSN. 4. Creating a Linked Server against MySQL SugarCRM database.

Creating a Linked Server against MySQL SugarCRM Database


To create a Linked Server against MySQL SugarCRM database, perform the following steps: 1. Installing the MySQL ODBC Driver. 2. Configuring MySQL DSN. 3. Configuring Microsoft OLEDB Provider for ODBC Drivers (MSDASQL) to use the MySQL Connector/ODBC DSN.

Installing MySQL Driver


To configure the Linked Server, you need to use the ODBC Driver specific to MySQL Data Source. Download and install MySQL Connector/ODBC 5.1.

Configuring MySQL DSN


A Database Source Name (DSN) specifies a data structure that contains the information about a specific data source that an ODBC driver needs in order to connect to it. To configure MySQL DSN, use ODBC Data Source Administrator. The ODBC Data Source Administrator is a Windows component to create and manage ODBC data sources. To configure the MySQL DSN, perform the following steps: 1. In the Run dialog box, type the command odbcad32 to start the program ODBC Data Source Administrator.

2. In System DSN tab, click Add to create the MySQL System DSN.

3. Select MySQL ODBC 5.1 Driver and click Finish. 4. Click Finish. The Operating System displays the MySQL Connector/ODBC 3.51 Data Source Configuration window. You can specify all the connection setting parameters for connecting SQL Server to MySQL in this window.

10

5. After you have entered all the required parameters, click Test to ensure that a connection can be made to the MySQL server.

6. Click Details to view the section where you can specify optional parameters to MySQL Connector/ODBC Driver. You can set some additional options to optimize the connection between the servers.

11

7. Select the optional parameters in Flag1, Flag2, and Flag3 tabs as specified in the following table: Tab F Flag 1 Flag 2 Option to Check Allow Big Results Use Compression Dont Cache Result of forward- only cursors Force Use Of Forwardonly cursors Purpose Do not set any packet limit for results and bind parameters. Use the compressed client/server protocol. Do not cache the results locally in the driver, instead read from server. This works only for forward-only cursors This flag needs to be set for non-cache result sets.

Flag 3 8. Click OK.

Configuring MySQL
To configure MySQL, perform the following steps:

12

1. Start the application SQL Server Management Studio to view the properties window of Microsoft OLEDB Provider for ODBC Drivers.

2. Select Object Explorer->Linked Servers-> Providers->MSDASQL. 3. Right-click and select Properties.

4. Select the following options for this provider: Nested queries

13

Level zero only Allow inprocess Supports Like operator

Creating the Linked Server to MySQL SugarCRM Database


On the Codeplex SSRS SDK project site (http://ssrsphp.codeplex.com/releases/view/43500 ) you can download the script mentioned thereafter, that can be used to automate the creation of Linked Server against SugarCRM database. To setup the Linked Server, perform the following steps: 1. Run cmd.exe (C:\Windows\System32\cmd.exe) with administrator privilege to invoke the sqlcmd utility. The sqlcmd utility allows you to enter Transact-SQL statements, system procedures, and script files at the command prompt. You can find this utility at C:\Program Files\Microsoft SQL Server\100\Tools\Binn.

2. Type cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn in the command window and press ENTER to change the current working directory to the location of sqlcmd.exe.

14

3. Use the sqlcmd utility to run the script file (.\..\Samples\SugarCRM\sugarcrm_linkedserver.sql) to create a linked server. sqlcmd S ./SQLEXPRESS i [file_path]\sugarcrm_linkedserver.sql If you are using any SQL instance other than SQL Express (ex: SQL Server), then you need to change the instance name accordingly. For example: sqlcmd S . i [file_path]\sugarcrm_linkedserver.sql Execution of this script creates the linked server (with name LS_SUGARCRM_MYSQL), a database (with name SugarcrmMySQL), and creates views in this database that map to the corresponding tables in MySQL sugarcrm Database. 4. Open and verify SQL Express Management Studio to make sure that the linked server and the SugarCRM database has been successfully created. 5. In the SugarCRM configuration, specify a username/password to connect to SSRS Server. The same users must have DataRead permission on the new DB (SugarcrmMySQL).

15

16

Deploying a Sample SugarCRM Report Solution


To deploy a sample SugarCRM report solution, perform the following steps: 1. Go to Start -> All Programs -> Microsoft SQL Server 2008 and start the application Business Intelligence Development Studio with administrative privileges. 2. Click the File menu, point to Open and then click Project/Solution. 3. Browse to ./../samples/SugarCRM/SugarCRM_Reports/Sugarcrm, and select the file Sugarcrm.sln and click Open.

4. In the ReportData Pane, double-click on the DataSource1 data source node. The application displays the Data Source Properties Window.

17

The value of connection string is Data Source=.\SQLEXPRESS;initial Catalog=SugarcrmMySQL. Note: If you are using any SQL instance other than SQL Express (for example: SQL Server), then change the value of DataSource in the connection string accordingly. For example: Data Source=.;initial Catalog=sugarcrmMySQL 5. In the Solution Explorer, right-click on sugarcrm, and select Properties to open the Solution Properties window.

18

Ensure that the value of TargetServiceURL contains the URL that points to the report server and click OK. The SugarCRM reports are now deployed.

Viewing the Deployed SugarCRM Reports in Report Viewer


To view the deployed SugarCRM, perform the following steps: 1. Open the Browser Report Manager using the following link:
http://localhost/Reports_SQLEXPRESS/Pages/Folder.aspx?ItemPath=%2fSugarcrm&ViewMode =List

The browser displays a list of SugarCRM reports.

19

2. Click on the required report name to view the corresponding details of the report. The browser displays the details of the report.

20

Step 2: Installing SQL Services Reporting Module in SugarCRM


This lab scenario shows how to install the sample SRSS module in SugarCRM.

Adding the Reports Module in SugarCRM


You can add and create custom modules in SugarCRM. You can create a module and add code which uses SSRS SDK for PHP to perform the following tasks: Connect to report server Retrieve the list of SugarCRM reports and display list of the reports Render the report when the user chooses any of the reports

The SSRSReport package is a sample package which includes a module to list and render SugarCRM reports. You can import this module into the SugarCRM application. To import the module into the SugarCRM application, perform the following: 1. Login to the SugarCRM as admin.

2. Go to Admin -> Developer Tools -> Module Loader.

21

3. Select the zip file \samples\ SugarCRM\project_Reports2009_10_31_074917.zip using the Browse button and click Upload. project_Reports2009_10_31_074917.zip is a sample SSRS module which shows how SSRS reports can be used within the SugarCRM. The module connects to SSRS server and displays the reports available in the SugarCRM dashboard.

4. Go to Admin -> Module Loader and click the Install button to install the module listed.

5. Go to Admin -> Module Builder -> Reports Package in the left pane and select Deploy.

22

The application displays a new link SSRS Reports under the tab Reports.

If the SSRS Reports link appears under Other tab as shown in the below diagram, then you can move it under the Reports tab by configuring in the Configure Tabs Group section.

To move the SSRS Reports link under the Reports tab, go to Admin -> Developer Tools Section > Configure Tabs Group. Drag the SSRS Reports under Others group and drop it into the Reports group. Click Save and Deploy.

23

6. Copy and paste the provided \samples\ SugarCRM\index.php and config.ini file to [sugarcrm_installation_path]\sugarcrm\modules\SSRS_Reports folder.

7. Create a folder images under [sugarcrm_installation_path]\ modules\SSRS_Reports with write permissions and copy the file .\..\samples\ SugarCRM\web.config into this folder.

24

8. Type the username, password and service URL in the config.php file. These details are required to access the reporting server. 9. Click Reports->SSRS Reports to see the list of reports.

10. Click on any report link shown in the dashboard to view the details of the corresponding report. The SugarCRM application displays the selected report within the dashboard

25

26

Step 3: End User Experiences


This lab scenario demonstrates how to create a new report in Report Designer and view the report within the dashboard of SugarCRM. Report Designer is hosted in the Business Intelligence Development Studio, which is fully integrated with the Microsoft Visual Studio 2008 development environment. If you do not have Visual Studio 2008 installed, SQL Server Setup installs the shell so that you can run Report Designer (more details at http://msdn.microsoft.com/en-us/library/ms157166.aspx)

Creating a New Report in Report Designer


This lab consists of the following two activities: Creating a Shared Data Source for the report Creating a new report

Creating a Shared Data Source for the report


To create a Shared Data Source in Visual Studio Report Designer, perform the following steps: 1. Go to Start -> All Programs -> Microsoft SQL Server 2008 and start the application Business Intelligence Development Studio using administrative privileges. 2. Click the File menu, point to Open and then click Project/Solution. 3. Browse to ./../samples/SugarCRM/SugarCRM_Reports/Sugarcrm, select the file Sugarcrm.sln and click Open.

27

4. In the Solution Explorer pane, right-click on Shared Data Source and click Add New Data Source to add a new shared data source.

28

The application displays the Shared Data Source Properties dialog box.

5. In the Name text box, type the name of the data source. 6. Click Edit to set the connection properties for the new data source. The Connection Properties dialog box appears.

29

7. In the Server name box, type the name of the server. 8. Select the option Use Windows Authentication. 9. Select the option Select or enter a database name. 10. Select the database SugarcrmMySQL from the drop down list.

11. Click Test Connection.

30

You can view the following dialog box if the database connection is successful.

12. Click OK in the Connection Properties dialog box. The Shared Data Source Properties dialog box appears.

13. Click OK in the Shared Data Source Properties dialog box. The new data source appears under the Shared Data Sources in the Solution Explorer pane.

31

Creating a New Report in Visual Studio Report Designer


To create a new report in Visual Studio Report Designer, perform the following steps: 1. In the Solution Explorer pane, right-click on Reports and select Add New Report.

The Report Wizard appears.

32

2. Click Next. 3. Select the option Shared Data Source. 4. Select the data source name that you gave while creating the data source.

5. Click Next. The Report Wizard dialog box refreshes to show the Query Builder button.

33

6. Click Query Builder to build the query. The Query Designer dialog box appears.

7. In the Query Designer dialog box, right-click on the white space and select Add Table.

34

The Add Table dialog box appears.

8. In the Views tab, select the required view and click Add. A dialog box appears which shows the fields of the selected view.

35

9. In the Query Designer dialog box, select the required fields and click OK. The Report Wizard dialog box appears.

10. Click Next.

11. Click Tabular. 12. Click Next. The Report Wizard allows you to design the report.

36

Select the required fields.

13. Click Next. 14. Select the type of layout you require for the table.

37

15. Click Next. 16. Select the type of layout you require for the table.

17. Click Next.

38

18. Type the name of the table in the Report name text box.

19. Click Finish. You can now view the new report in the Solution Explorer pane of Visual Studio Report Designer.

20. In the Solution Explorer pane, right-click the new report you created and click Build.

39

Visual Studio Report Designer builds the report.

21. In the Solution Explorer pane, right-click the new report you have created and click Deploy.

40

Visual Studio Report Designer deploys the report.

22. In the Solution Explorer pane, right-click the new report you created and click Run.

41

Visual Studio Report Designer runs the report and displays the report in a new window.

42

Viewing the New Report in Reports Viewer


To view the new report in Reports Viewer, perform the following steps: 1. Open the Browser Report Manager using the following link:
http://localhost/Reports_SQLEXPRESS/Pages/Folder.aspx?ItemPath=%2fSugarcrm&ViewMode =List

The browser displays a list of SugarCRM reports. You can see that the Browser Report Manager displays the name of the new report.

2. Click on the new report you created to view the corresponding details of the report. The browser displays the details of the report.

43

Viewing the New Report in SugarCRM


To view the new report in Reports Viewer, perform the following steps: 1. In the SugarCRM dashboard, click on Reports->SSRS Reports to see the list of reports. You can view the new report that you created in the list of reports.

44

2. Click on the new report link that you created to view the details of the corresponding report. The SugarCRM application displays the details of the selected report within the dashboard.

45

46

The Interop Vendor Alliance


The Interop Vendor Alliance is an industry group working to identify and share opportunities to better connect people, data, and diverse systems through better interoperability with Microsoft systems and to jointly market the interoperability solutions of its members. The organization serves as a collaborative forum for developing and sharing common technology models, facilitating scenario-based testing of multivendor solutions, and communicating additional best practices to customers and partners. Since its formation in 2006, alliance membership has more than doubled as the IVA has developed multiple interoperability labs, including System Management, Centralized Directory, Federated Identity, Content Management, and Open XML. You can learn more by visiting http://interopvendoralliance.com/.

47

This document is provided as-is. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. You may modify this document for your internal, reference purposes. Distributed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0

48

You might also like