programming4us
programming4us
WEBSITE

Microsoft SharePoint 2010 : InfoPath Forms Services - Accessing Data in InfoPath Forms (part 1)

11/20/2014 3:10:34 AM

One of the powerful features of InfoPath, especially when it comes to generating browser-based forms, is the ability to connect to additional data sources. We can reuse our earlier Demonstration Equipment Request form to see this in action.

  1. Open the EquipmentRequest.xsn file from the local file system. Our form has two sections: the top section captures customer details and the bottom section captures a list of products. Rather than manually keying in customer details, we’ll make use of a SQL Server database to look up the required information and automatically populate the fields.

    Tip

    For demonstration purposes, SQL connections are easiest to use. However, their usefulness within InfoPath forms is pretty limited. Passing parameters generally requires custom code, as you’ll see later. As a general rule, the best way to communicate with external data sources is to create a custom web service interface. InfoPath can then parse the Web Service Definition Language (WSDL) and create fields for any parameters that may be required.


    To provide some sample data to work within our various examples, we need to download and install the SQL Server 2008 sample databases, which can be found at www.codeplex.com/MSFTDBProdSamples. Our examples make use of the AdventureWorksLT database installed on the local instance of SQL Server 2008.

  2. At the bottom of the Customer Details section, add a button. Buttons and other controls can be found in the Controls section of the Home ribbon. Type the button label as Find Customer.

  3. To add a data connection, switch to the Data tab on the ribbon, and then click From Other Sources | From Database, as shown:

  4. Click Select Database to select from the data sources that are available on the current machine. If one is not available for the AdventureWorksLT database, click New Source to add one. Select the Customer table when prompted. Once the data connection has been made, the columns will be listed, as shown next:

  5. Since we want to use a query to extract data from more than one table, click Edit SQL and enter the following SQL statement:

    Select            C.CustomerID,
    C.CompanyName,
    A.AddressLine1,
    A.AddressLine2,
    A.City,
    A.StateProvince,
    A.PostalCode
    From SalesLT.Customer as C
    Inner Join SalesLT.CustomerAddress as CA
    On CA.CustomerID=C.CustomerID
    Inner Join SalesLT.Address as A
    On A.AddressID=CA.AddressID

  6. Click Next. Leave the Store A Copy Of The Data In The Form Template checkbox unchecked. Click Next and then uncheck the Automatically Retrieve Data When Form Is Opened checkbox. Set the connection name to Customer and then click Finish to create the connection.

  7. We’ll make use of the Company Name field to search for customers. All other fields will be populated automatically from the search results. To make all other fields read-only, select the field and then from the Properties tab of the ribbon, check the Read-Only option in the Modify section. Repeat this process for all fields in the Customer Details section other than the Company Name field.

  8. We’ll display our search results on a separate page. From the Page Design tab’s Views section, select New. Name the new view Customer Search Results.

  9. Type the title of the new view as Customer Search and then, from the Fields pane, in the Fields drop-down, select Customer (Secondary). (The Fields drop-down is something of a misnomer. In reality, the drop-down contains a list of the data connections that are available to the current form.)

  10. Drag the d:Customer repeating group onto the Customer Search form. Select Repeating Table as the control type. When producing a schema from a SQL statement, InfoPath also adds columns for both sides of a join relationship. As a result, three redundant columns are named CustomerID1, AddressID, and AddressID1. To remove these from our repeating table, simply select the offending columns and choose Delete | Columns from the Layout tab.

  11. Since we don’t want the user to be able to edit the contents of these fields, using the Change Control button on the Properties menu that we demonstrated earlier, change the controls to Calculated Values.

  12. The final item that we need to add to our search form is a button to select the correct customer. Place the cursor in the first column of the table and then, from the Table tab in the ribbon, click Insert Left.

  13. Add a button in the data area of the new column and type the label as Select. The completed form should look like this:

Other  
  •  Extra-Curricular Activity - BMW 218d Active Tourer SE - An Engine That’s Fit For A Juke - Nissan Juke Tekna DIG-T (Part 1) - BMW 218d Active Tourer SE
  •  The Porsche Macan S Diesel 3.0 V6 – The Ultimate SUV You Can Drive (Part 2)
  •  Sharepoint 2010 : InfoPath Forms Services - InfoPath Overview (part 5) - Using InfoPath Forms in SharePoint - Creating Document Information Panels
  •  Sharepoint 2010 : InfoPath Forms Services - InfoPath Overview (part 4) - Using InfoPath Forms in SharePoint - Adding Formulae to Fields, Publishing a Form Template to SharePoint
  •  Sharepoint 2010 : InfoPath Forms Services - InfoPath Overview (part 3) - Using InfoPath Forms in SharePoint - Creating Form Templates
  •  Sharepoint 2010 : InfoPath Forms Services - InfoPath Overview (part 2) - BrowserForm Web Part
  •  Sharepoint 2010 : InfoPath Forms Services - InfoPath Overview (part 1)
  •  Sharepoint 2013 : List and library essentials - Sorting and filtering lists
  •  Sharepoint 2013 : List and library essentials - Using list and column validation rules
  •  Sharepoint 2013 : List and library essentials - Editing and deleting list columns
  •  
    GTS - youtube channel
    video
     
    Video tutorials
    - How To Install Windows 8

    - How To Install Windows Server 2012

    - How To Install Windows Server 2012 On VirtualBox

    - How To Disable Windows 8 Metro UI

    - How To Install Windows Store Apps From Windows 8 Classic Desktop

    - How To Disable Windows Update in Windows 8

    - How To Disable Windows 8 Metro UI

    - How To Add Widgets To Windows 8 Lock Screen

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010
    programming4us programming4us
    programming4us
     
     
    programming4us