Add a data connection to a SharePoint document library or list in InfoPath

Add a query data connection
To allow users to query data from a document library or list on a site that is located on a server running Microsoft Windows SharePoint Services, you need to do the following in the form template:
1.    Add a secondary data connection.
2.    Configure the form template to use the secondary data connection.
Step 1: Add a secondary data connection
1.    On the Tools menu, click Data Connections.
2.    In the Data Connections dialog box, click Add.
3.    In the Data Connection Wizard, click Create a new connection to, click Receive data, and then click Next.
4.    On the next page of the wizard, click SharePoint library or list, and then click Next.

5.    On the next page of the wizard, type the URL of the SharePoint site with the document library or list, and then click Next. For example, to use a document list on a SharePoint site with the URL http://www.adventureworks.com/EmployeeList, you type http://www.adventureworks.com/EmployeeList.
6.    On the next page of the wizard, in the Select a list or library list, click the list or library that you want to use, and then click Next.
7.    On the next page of the wizard, select the check boxes next to the values that you want to receive. If the form template will be published to the document library, and you want forms that are based on this form template to get metadata about the form, select the Include data for the active form only check box.
8.    Click Next.
9.    If you want to store the results of the query with the form template, select the Store a copy of the data in the form template check box. Selecting this check box stores the query results in the form template. Because the data is stored in the form template, the data is available in the forms that users fill out, even if their computers are not connected to a network.
Security  Selecting this check box stores the query results in the form template. Because the data is stored in the form template, it is available in the forms that users fill out, even if their computers are not connected to a network. If you are getting sensitive data from this data connection, you may want to disable this feature to help protect the data in case the computer is lost or stolen.
10.  Click Next.
11.  On the next page of the wizard, in the Enter a name for this data connection box, type a descriptive name for this secondary data connection. This is the name that appears in the Data source list in the Data source task pane. If you want this query to run automatically whenever the form is opened by a user, select the Automatically retrieve data when form is opened check box.
Step 2: Configure the form template to use the secondary data connection
If you want forms that are based on your form template to use this data connection after the user opens the form, you can add a rule to the form template that uses this data connection under a certain condition, or you can add a button to the form template that users can click to use this data connection.
Add a rule
You can add a rule to the form template to get data from the query data connection whenever the condition for the rule is met. The following procedure assumes that you have created a query data connection for your form template, and that you have configured a control on your form template to display the data from that data connection.
1.    If the form template has multiple views, click View name on the View menu to go to the view with the control where you want to display the data from the secondary data source.
2.    Double-click the control that you want to display the query results.
3.    Click the Data tab.
4.    Under Validation and Rules, click Rules.
5.    In the Rules dialog box, click Add.
6.    In the Name box, type a name for the rule.
7.    To specify a condition when the rule should run, click Set Condition, and then enter the condition. The rule will run when the condition occurs. If you do not set a condition, the rule will run whenever the user changes the value in the control, and then moves his or her cursor away from that control.
8.    Click Add Action.
9.    In the Action list, click Query using a data connection.
10.  In the Data connection list, click the query data connection that you want to use, and then click OK to close each open dialog box.
11.  To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.
Add a button
You can add a button control to your form template that your users can click to use this query data connection. The following procedure assumes that you have created a query data connection for your form template.
1.    If the form template has multiple views, click View name on the View menu to go to the view with the control where you want to display the data from the secondary data source.
2.    If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
3.    Drag a button control onto your form template.
4.    Double-click the button control that you just added to your form template.
5.    Click the General tab.
6.    In the Action list, click Refresh.
7.    In the Label box, type the name that you want to appear on the button on your form template.
8.    Click Settings.
9.    In the Refresh dialog box, click One secondary data source.
10.  In the Choose the secondary data source list, click the secondary data source that is associated with the query data connection, and then click OK to close each open dialog box.
11.  To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.
Add a submit data connection
To allow users to submit forms that are based on your form template to a document library, you need to do the following:
1.    Add a secondary data connection that submits data to your form template.
2.    Configure the form template to allow your users to submit their form data to the document library.
Step 1: Add a secondary data connection
1.    On the Tools menu, click Data Connections.
2.    In the Data Connections dialog box, click Add.
3.    In the Data Connection Wizard, click Create a new connection to, click Submit data, and then click Next.
4.    Under How do you want to submit your data, click To a document library on a SharePoint site, and then click Next.
5.    In the Data Connection Wizard, in the Document library box, type the URL of the SharePoint document library.
6.    In the File name box, type a name that will be used to identify the form in the document library.
 Tip   You can also use a formula to ensure that each form name is unique.
How?
1.    Click Insert Formula .
2.    In the Insert Formula dialog box, do one of the following:
§ To use a field in the formula, click Insert Field or Group, click the field that you want to use in the Select a Field or Group dialog box, and then click OK.
§ To use a function in the formula, click Insert Function, select the function that you want to use in the Insert Function dialog box, and then click OK.
 Tip   If the function requires parameters, select the function in the Insert Function dialog box, click OK and then, in the Formula box in the Insert Formula dialog box, double-click the function that you added, and click a field or group. Find links to more information about functions in the See Also section.
§ To insert a value or mathematical operator into the formula, type the value or the symbol for the mathematical operation in the Formula box.
Operation
Symbol
Add
+
Subtract

Multiply
*
Divide

Advertisements

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