Muhammad Ali Khan

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

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.

Advertisements

13 Responses to “Using Business Connectivity Services(BCS) In SharePoint 2010 For Connecting To MS CRM 4.0”

  1. […] Using Business Connectivity Services(BCS) In SharePoint 2010 For Connecting To MS CRM 4.0 […]

  2. Radhika said

    I have used your sourceCode to retrieve the Accounts information and ofcourse changed the url while deploying, however received an error while deploying like :No default Business Connectivity is availabe for the specified SPContext, so have to create new BDC connection in Manage Service Connections and specified the endpoints and deploy was successful. NOW the problem is i receive an error when trying to retrieve the account data using the url.
    http://vmsp2010/sites/eventregistration/_bdc/MSCRMBdcModel_BdcModel1/Account_1.aspx?AccountID=0

    ERROR Message:

    MSCRMBdcModel.BdcModel1.Account

    An error occurred while retrieving data from MSCRMBdcModel. Administrators, see the server log for more information.

    Please let me know how to handle this. Your help is very much appreciated.

    thanks,
    Radhika.

  3. Poojith said

    I can’t create and associate the custom forms with the external list in SharePoint Designer. Giving error “Could not save the list changes to the Server”..Any idea?

    • Ali Khan said

      Hi Poojith,
      This is a very generic error. Can u have more details on the above. Also check the event log, Are u using Sharepoint 2010 Beta, Do u have permission on the site for this action?

  4. thakhi said

    Hi Ali

    I am also getting the same error
    Could not save the list changes to the Server in designer and edit,new item,delete buttons are disabled and showing this control is currently disabled

    Thanks
    Thakhi

    • Ali Khan said

      Hi Thakhi,

      Are you able to create New/Edit form for other list(other than BCS list)? I am sure you will get an error there as well. The problem is either with Sharepoint2010 Desinger Installation or you dont’ have permission. Can u check the event log?
      One more thing are u using 32 bit of designer?

  5. Ahmad said

    The same error here “Could not save the list changes to the Server”.

    I am using sharepoint 2010 beta and sharepoint designer 2010 64 bit.

    Thanks in advance.

  6. xyz said

    I was able to solve “Could not save the list changes to the Server” error from the following links:

    http://nickhadlee.wordpress.com/2010/05/24/the-content-type-is-in-use-sharepoint-2010-error-redux/

    http://mqsharepoint.blogspot.com/2009/01/content-type-is-still-in-use.html

    http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/eba4cd7e-498a-465f-adea-decae44d7a8c

  7. Jurgis said

    I have tried this with MS CRM 2011 but got this error:
    MethodInstance with Name ‘ReadItem’ on Entity (External Content Type) with Name ‘Account’ in Namespace ‘MSCRMBdcModel.BdcModel1’ failed unexpectedly. The failure occurred in method ‘ReadItem’ defined in class ‘MSCRMBdcModel.BdcModel1.AccountService’ with the message ‘Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/.’.

    Please let me know how to handle this. Your help is very much appreciated.

    Thanks,
    Jurgis

  8. Mohamed said

    Hi Ali,
    Thank you for this helpful post. I am using BCS to retrieve data from a third-party app. We don’t want to pass the current user credentials. Instead, we will be using a pre-determined set of credentials from the third part application. However, this application allows only 5 simultaneous sessions per set of credentials. Thus, we will not be able to map all users to one set of credentials. I am considering the options I have.
    One would be to write an application that will map each 5 of our users to a set of credentials inside BCS. This way, we ensure all users can connect. However, whenever a user joins the company, we have to map them to a set of credentials in BCS.
    The second option would be when the BCS is retrieving data, we check which set of credentials from the third-party app has less than 5 current sessions and use that. However, I am not sure this is feasible.
    Is there any guidance or advice you can provide on how to proceed?
    Thank you.

    Regards,

    Mohamed

  9. ajnar said

    Trying to create an external content type for Dynamics AX 2012 but cant seem to read the service endpoints from designer 2010.
    Keeps telling me not valid xml returned but when i ran the url on a broswer i actually get the xml

  10. Ajith said

    Was anybody able to solve the “could not save the list changes to the Server” Problme? For me it also an Edit Form is created when I create an external List. But I do not see the fields I have in display mode.
    What might be wrong?
    By the way I can create new forms for other custom list

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: