Consuming External Content Types(BCS) in InfoPath Forms

Business Connectivity Services(BCS) is one of the coolest features in SharePoint 2010.  BCS helps us connect to Line of Business applications without writing a single line of code.

In this article, we will explore the process to connect to BCS and use the information within an InfoPath form.  A business scenario would go something like this

“You need to create a Expense Report form.  Users entering expenses will need to pick a valid project from your Line of Business system within the InfoPath form”

Check out these articles on how to create the BCS model and connect to your Line of Business system

Tobias’s Article on BCS

Now that you have a BCS system, lets display those fields within an InfoPath form

In my example, I have a simple SQL Table with a list of projects as shown below


We need to build an InfoPath form where users can pick one of the projects from this list.

My external content type in SharePoint Designer looks like this below


Notice the following properties ‘coz you will need them when you build your form in InfoPath

Name, Namespace, External System

Open up InfoPath 2010 and design a blank form

In the Home Tab, Under the Controls section choose the External Item Picker option under the input sub section and add it to the form


InfoPath will add a new group to the data fields with some properties.

Add the Field to the InfoPath form, right click and pull up the Properties for the external Item Picker


Enter the Namespace of your ECT , Name of the ECT and the System Instance Name(in our case it is CRM) into the required fields. <edit>Enter the Display Name of your field, otherwise you would only the see the identifier when you preview the form..</edit>

Note: After two hours of frustration, I found this to help finding information about the system instance name.  There is no help for the required fields and at first I couldnt figure out what the “System Instance Name” was.  Is it the name of the Finder ? Is it the name of the Entity? .   A search on MSDN retrieved the following article

MSDN System Instance Article

The System Instance name is a property of the SPBusinessDataField.  So to find out the property, I added the same field to a custom list and wrote some code as follows to retrieve the System Instance Name


The system Instance name was the same name as the external system property in SharePoint Designer.

Click the Other Settings tab in Infopath and set the following properties.  Check the “Refresh on Open” option and select the dropdown for the picker mode to “Connect to external data through SharePoint”


Click Ok and Hit Form Preview. Now you can search for content in your LOB and surface them through InfoPath.  We will discuss saving this data to SharePoint in another post.


Close InfoPath Forms Services form using Code

I was working on a way to close an InfoPath form using C# or VB.NET from the form code-behind after the user submits the form. The steps below help in running some custom code to save the data and then close the form.

Here are the steps to close the Form

  • Set the Submit Action[Tools->Submit Options] within InfoPath for the form to “Perform custom action using Code” . Click the Edit Code option to submit the form using code
  • Set the After Submit option under Advanced to “Close the Form”


Click the Edit Code button next to the perform custom action to submit the data. Editing the code adds an handler for the Form Submit event and a FormEvents_Submit method is created in the code behind. Once the code completes the submission, set the CancelableArgs.Cancel property of the SubmitEventArgs to false.

Here is a sample FormEvents Submit method

In the SubmitConnection method, I retrieve the required data connection and call the execute method for submission

Dim fileSubmit as FileSubmitConnection = CType(Me.Connections(“SharePoint Save”),Microsoft.Office.InfoPath.FileSubmitConnection)


In the above sample, the data connection that I want to use for Submit is named “SharePoint Save”. I typecast it as a FileSubmitConnection.

I found this solution on one of the forum posts

%d bloggers like this: