Muhammad Ali Khan

MS CRM 3.0, MS CRM 4.0, Sharepoint 2007 & Sharepoint 2010

Archive for the ‘Bussiness Connectivity Services’ Category

Relating/Connecting MS CRM 4.0 Data With Custom External Content Type Data In SharePoint 2010

Posted by Ali Khan on February 4, 2010

In this post, i will first display the data from MS CRM 4.0 and from my custom external type(SQL Server Database) in my SharePoint 2010 portal and then show you how to relate(connect) these two different external content type. I got this idea from the “Fabain Williams SharePoint” blog from here SharePoint 2010 Business Connectivity Services Teaser with Multiple External Content Types surfacing in One External List.

As i saw the above post, i thought i could use it to solve my old problem in SharePoint 2007 :). I remember last year one of my customer asked me to display and relate the data from MS CRM 4 and Axapta on SharePoint portal and i end up writing my own custom Web part, since there exits no relationship between these two external content type in MOSS 2007.

Note:- There exits NO PHYSICAL RELATIONSHIP between the two external content type i am going to use below. So here we go:-

Step 1: Setup the MS CRM Account External Content Type:-

First i have to setup my external content type to fetch data from MS CRM 4. I already did that in one of my earlier post. You can see the complete post here (Using Business Connectivity Services(BCS) In SharePoint 2010 For Connecting To MS CRM 4.0). Here is how MS CRM Accounts look like. (The important field to note here is the “AccountNumber” since we will be relating the two external content type on this column).

image

Step 2: Setup the Other External Content Type(SQL Server Database):-

I then created another “External Content Type”, this time to a SQL Server Database, for this you can use this post from Microsoft (How to: Create an External Content Type Based on a SQL Server Table).

Here is how my table(CompanyProjects) in custom database look like. This tables contains the list of the projects against a particular MS CRM Account. As you can see i have put the AccountNumber field in both “MS CRM External Content Type” (above) and in my custom (CompanyProjects) table below, since we will be relating(connecting) the data from these two different source on this field.

image

and here is the data i manually put in.

image

The next step is to create the external content type for the above table( you can do it by following the steps here How to: Create an External Content Type Based on a SQL Server Table). And then i created a SharePoint 2010 List for this external content type, see below. (The important field to note here is the “AccountNumber” since we will be relating the two external content type on this column).

image

Step 3:- Create the “Site Page” which will host these two external content type:-

Go to Site Actions ==> New Page. A New Page Dialog will popup. Name the page and click create.

image

It will open the page in the design mode, now we will insert our two external content type. Click on the “Insert” ribbon, and then click on the “Existing List” button. Select “MS CRM Accounts” list and then click add.

image

image

Here is it how it looks like now. (Note by default the view of the WebPart will be show only the BDC Identity, Edit the WebPart and select the view to your desired view). Note the “AccountNumber” in the below view.

image

Similarly, click on the add “Existing List” button and add the “My Custom Projects” list this time. The whole page will now look like this. Note again the “AccountNumber” in the list.

image

As you can see, both our MS CRM Account and our other external content type (Projects) are on the page now, showing the complete data from both the list. Now the final step is to relate/connect these two lists.

Step 4:- Relate/Connect the Two External Content Type:-

In the SharePoint 2010 portal, Click “Page” ribbon and then from the “Edit” dropdown, select “Edit in SharePoint 2010” Designer, this will open the page in “SharePoint 2010” designer.

Once in SharePoint 2010 designer, select the “MS CRM Account” web part and click “Add Connection” in the ribbon.

image

Now we will create the relationship (well its not really a relationship, its just a connection) between the two WebParts below. A wizard will startup, here is the step by step process to create this connection.

image

image

image

image

Make sure you select the correct columns while defining this connect from both list (i.e. AccountNumber)

A connection between two webparts is now setup. Save the Page in SharePoint 2010 designer, and the open the page in the browser. Here is how the page now looks like. Click on any MS CRM Account Row (Click on image ICON to select the row)

image

image

You can see now the “Project List” is now filtered on the MS CRM Account you selected from the above List (Based on the “Account Number”).

All i can say “Coooooool”. i remembered i had to write a custom WebPart for this to happen in SharePoint 2007.

Actually, i didn’t stop here :), in fact i created one more relationship between my “Custom Projects” and the details of the Tasks “Task List”. so my projects will be filtered on the selected “MS CRM Account” and then my “Tasks” list will be filtered on my selected “Custom Project”. Here is how it looks like. (i am sure you can follow and repeat the above steps to achieve this).

image

So the connection between MS CRM Account and Custom Project is on “AccountNumber” and the connection between “Custom Project” and “Task List” is on “ProjectId”.

Finally, does it means, we don’t have to create our own WebPart for displaying related data from two different “External Content Type”. Well off course not, SharePoint 2010 does provide you a very good platform for connecting non-related “External Content Type” with features of sorting, filtering, creating custom views with basically no code. But there may still exits scenarios where you have to create your own WebPart.

That’s all for now.

Advertisements

Posted in BCS, Bussiness Connectivity Services, MS CRM 3.0, MS CRM 4.0, Sharepoint 2010, SharePoint 2010 Designer, Sharepoint Foundation 2010 | Tagged: | 3 Comments »

Using Business Connectivity Services(BCS) In SharePoint 2010 For Connecting To MS CRM 4.0

Posted by Ali Khan on January 24, 2010

In this post i will create a custom BCS .net connector (for SharePoint 2010) in Visual Studio 2010  to connect to MS CRM 4.0 and perform the basic CRUD(Create, Retrieve, Update, Delete) operations on the MS CRM “Account” Entity.

Source Code:- You can Download the Source Code of this Project From Here, Source Code.

Step 1:- Create a Custom .Net BCS Project In VS2010 For MS CRM 4.0

As First Step, Open VS 2010 (Beta 2 Ultimate Edition), Go to File==>New==>SharePoint 2010 ==> Business Data Connectivity Model Project.

Since VS2010 has the built in support for editing the application definition file, it will give me a nice GUI BDC Editor, After renaming the default “Entity1” and adding CRUD methods, it will look like this.

image

You can use the “BDC Method Details” window (the 2nd window in the above diagram) to create new Methods, as shown in the diagram below.

image

There is also the BDC Explorer on the right side. You can use the BDC Explorer to create “Methods In & Return Parameters” Here is how it look like.

image

Simply right click on the parameter name and click on “Add Type Descriptor” and then you can define the “Account” entity, as shown below.

image

If you want to use the VS2010 BDC Editor, Here is a good article as a starting point on how to use the editor (Building a BDC Model using the .NET Assembly Connector). But i personally like the XML Editor more as i find more flexibility in it. So to open the XML Editor, Right Click on your Model File (MSCRMBdcModel.bdcm) in “Solution Explorer” and click “Open With” a “XML Editor”  to bring the Model XML Editor.

image

Here is how it looks like.

image

And here is our “Account.cs” Entity.

image

And the Implementation of all the “CRUD” Methods from MS CRM 4.0 in “AccountService.cs”

image

Now from the Solution Explorer, right click and click “Deploy”, it will package the solution and deploy the External BCS Content Type on the your SharePoint 2010 site. (Remember to change the SharePoint site URL in the project properties window)

image 

This is how it looks like in the “Central Administration”. you can configure permission on it by click on the drop-down menu and select “Permission”.

image

Step 2:- Configure External Content Type Profile Page In Centeral Administration

Now go to Central Administration ==> Application Management ==> Service Application ==> Business Data Connectivity and click “Manage” from the top Ribbon. You will see the screen below,

image

Click “Edit” from the Ribbon and select “Configure” to configure the path for the “Profile Page” and click ok. See the diagram below.

image

Generate the profile page for the External Content Type “Account” by click on the dropdown ==> “Create/Upgrade Profile Page”.

image

So Now if you browse to any MS CRM Account with the above URL (e.g. http://win-1r2gn7r1jaq:8000/_bdc/MSCRMBdcModel_BdcModel1/Account_1.aspx?AccountID={ADE922F4-6C06-DF11-BF5A-001E8CFDD686}), you will get a profile page for the MS CRM Account as shown below.

image

Step 3:- Create a “External Content Type” List To Host MS CRM 4.0 Account

Browse to the site, where you deploy the solution, go to Site Actions==> More Options ==> List ==> “External List” ==> Create. Here Select the “External Content type”, as show below, and click “Create”.

image

Now the list will shows all the accounts from MS CRM 4.0, as shown below.

image

Off course you can always change the List View and remove the “AccountID”, as it is a Guid and there is no point in showing it to the end user. Here is how it looks like now.

image 

Step 4:-  Using SharePoint 2010 Designer to Create the “New”, Edit Form for our External Content Type

If you click on “Add new Item” now, it will throw an error because the create and edit page doesn’t exit for the list. So lets create the “New” & “Edit” form for our list in SharePoint 2010 Designer.

Open your site in SharePoint 2010 Designer ==> List and Libraries ==> click “CRM Accounts” (Your external list) to see the diagram below.

image

As you can see there are now “Create” and “Edit” Forms in the “Forms section”. So click “New” in the form section to open up the dialog box as shown below (for the “Create Account”) and click ok.

image

Do the same for the “Edit Account”, but this time select “Edit item form”, your forms section will now look like this.

image

Now click on the “EditAccount.aspx” page and modify the view. Here in SharePoint 2010 Designer, you can decide which field to show and which one to hide from the end user. Here is how the “EditAccount.aspx” looks like in SharePoint 2010 Designer (after editing). As you can see we have deliberately hide the “Account ID” (a Guid) and Parent Account (A MS-CRM Lookup) on the Edit Form.

image

Save the forms. Now browse to your list (MS CRM Accounts) in the SharePoint site. Here is how the “Create Account” looks like.

image

And Here is “Edit Account” and “Delete” option. You can see below the “Account ID” and “Parent Account” are not visible as we removed these field in the SharePoint 2010 Designer.

image

Oh Yes, and here is how it looks like in MS CRM 4.0

image

With this example, now you can perform all the basic operations CRUD( Create, Retrieve, Update, Delete) on MS CRM Account inside your SharePoint 2010 Portal, thus opening new opportunities for integration between MS CRM 4.0 and SharePoint 2010 Portal.

That’s all folks.

Posted in BCS, Bussiness Connectivity Services, MS CRM 4.0, Sharepoint 2010, SharePoint 2010 Designer, Sharepoint Foundation 2010 | Tagged: , | 13 Comments »

Business Connectivity Services (BCS) Using WCF & SharePoint Designer 2010

Posted by Ali Khan on January 11, 2010

In this post, I will consume a simple WCF service in SharePoint 2010 Designer and create an external content type (formerly known as Entities in BCD).

Step 1:Create the WCF Service & Deploy In IIS

My First step is to create the WCF service. There is nothing fancy about the code, I have one simple “Project” Contract with CRUD methods defined (that later I will consume in BCS), these methods are using LINQ to SQL to my test SQL Server Database (ProjectDB). Here is the WCF Contract.

image

And here is its implementation

image

You can download the full code (along with the application definition file from here “Download Code, you can import this application definition file from the Central Administration).

Step 2: Create External Content Type In SharePoint Designer 2010 From WCF Service

After deploying the WCF service in IIS, now let’s move to SharePoint 2010 Designer and create the BCS External Content type from this WCF Service. Open any site in SharePoint 2010 Designer ==> Click External Content Types.

image

Click “External Content Type” in the Ribbon to create a new External Content type. Fill the “Name” and other properties as shown below.

image

Click the line “Discover external data source and define operations” and in the new screen, click “Add Connection” and select “WCF Service”.

image

Fill in the properties “Service Metadata URL”, “Service Endpoint URL” and namespace and the click ok. It will download the metadata from the WCF contract and generate the BCS External Content Type for you.

 imageAfter click ok, the external content type from WCF will look like this. Now you have to define the operations for this external content type.

image

Now one by one, you will generate the method for CRUD (Create, Retrieve, Update, and Delete) and Retrieve List. Here is the step by step procedure for the create method. Right click “Create” and select “New Create Operation”, a wizard will open up.

image

image

image

Now Click “Finish”, it will generate the “Create Method” for this external content type. Similarly, generate the method for other operations. Now your “External Content Type” will look like below,

image

Save the “External Content Type”, by pressing “Save Icon” in the SharePoint 2010 Designer at the top.

image

Step 3: Configure External Content Type Profile Page in Central Administration

Now go to Central Administration ==> Application Management ==> Service Application ==> Business Data Connectivity and click “Manage” from the top Ribbon. You will see the screen below,

image

Click “Edit” from the Ribbon and select “Configure” to configure the path for the “Profile Page” and click ok. See the diagram below.

image

Generate the profile page for the External Content Type “WCFProject” by click on the dropdown ==> “Create/Upgrade Profile Page”.

image

So Now if you browse to any project with the above URL (e.g. http://win-1r2gn7r1jaq:8000/_bdc/AliProjects_WCFSP2010/WCFProject_1.aspx?ProjectID=9e02b936-2d41-4031-a2f0-6b8e8c6367e8), you will get a profile page for the project as shown below.

image

Step 4: Displaying WCF Service Data In SharePoint List

Now we will create an “External List” to consume this data from WCF Service  as shown below.

image

image

Select the “External Content Type (WCFProject)” and click “Create” to create the list. It will pull the listings for all the projects from the WCF “ReteriveMultiple” Method as shown below.

image

Now you can “Create”, “Update”, “View” and “Delete” any “Project” and it will call WCF Method internally to perform the operation. See the example of the delete below.

image

Here is the “Create” form.

image

In Brief, With SharePoint 2010, now we can easily create connect our existing WCF Service with the SharePoint and display, edit,create and delete the data inside the portal.

That’s it :).

Posted in BCS, Bussiness Connectivity Services, Sharepoint 2010, SharePoint 2010 Designer, Sharepoint Foundation 2010, WCF | Tagged: | 11 Comments »