Using Secondary InfoPath Data Connections to retrieve data from a SharePoint List or Library - SharePoint Development & Administration + InfoPath

Tuesday, July 7, 2009

Using Secondary InfoPath Data Connections to retrieve data from a SharePoint List or Library

The following demonstrates how to use InfoPath data connections to connect to and retrieve SharePoint list contents (item metadata) for use in the form. This can be useful when InfoPath forms are used as a workflow component or interface, or if the form is being submitted to a library on a SharePoint site.

The example creates a secondary data connection that connects to a standard SharePoint task list. Some sample items have been added to the task list.

Article Specifications/Requirements
  • SharePoint (MOSS 2007) OOB Task List
  • Written for InfoPath 2007, but can also be applied to InfoPath 2003
Process

Create the blank form and set up the data connection:

  • From Microsoft InfoPath, design a new blank form template.
  • From the "Tools" menu, select "Data Connections". Click the "Add"button to add a new data connection to the form which will be a secondary data connection (not the main submit)
  • Select "Create new connection to", and "Receive Data"
  • When you are asked to select the source of your data, select "SharePoint library or list" from the options.
  • Enter either the URL/address of the SharePoint site with the source list or library and select the required list, or enter the full address to the list and view which will then select the list for you.
  • Select the fields/columns from the list that you required for the data connection.
  • Select "Store a copy of the data in the form template" if you would like InfoPath to store a copy or "snapshot" of the data/results from the from the list which makes the data source accessible to offline users who are using the form for the first time.
  • On the final screen, enter a name for the data connection, leave the "Automatically retrieve data when form is opened" option checked and press "Finish".

Add controls to display data from the data connection on the form


  • From the View menu or the Task Pane, select "Data Source"
  • From the data source drop-down list, select the data connection created
    in the steps above.
  • Expand the groups until you can at least see the repeating group.
    In this case the repeating group is named "Tasks", which is the name/title
    of the list that the data connection retrieves data from.
  • Right click on the repeating group and select "Repeating Table" from the
    options. This will add a table to the form view with a field for each
    node/element in the data source.
  • Adjust the width of the table cells to an appropriate size for each
    field/column
  • Save the form template if you haven't already done so.
  • You can now preview the form by pressing the "Preview" button on the
    toolbar or saving/publishing the template to SharePoint. For
    instructions and an example of how to publish or store a form template in a
    SharePoint library, see Submit InfoPath form to SharePoint List or Library using Content Type.

Note: If previewing from InfoPath you may be prompted about a "potential security
concern" relating to the form using your identity to connect to data
sources. This is a result of the temporary preview template being stored by
InfoPath in your user profile directory on the local computer. To
avoid this,save the form template to SharePoint by publishing to a site
content type or library. See article linked above (or related articles
below) for details.

Things to Know:
InfoPath data connections to a SharePoint list or library only retrieve the items from the list which are displayed in the default view, or the view specified when setting up the data connection.

For example, if the default view for the SharePoint list is set to limit or display items in batches of 100, the data connection will retrieve the same 100 items from the SharePoint list. You can either specify a custom view when setting up the data connection which displays all required items, but keep in mind the increase in processing requirements for both the client machine (InfoPath form user) and the SharePoint server. See
InfoPath Data Connections not returning all results for details.

Related:

See related article
Submit InfoPath form to SharePoint List or Library using Content Type for details and an example of how to submit an InfoPath form to a SharePoint form library, by publishing the form template to a site content type. Fields from the InfoPath form can be mapped to columns in the SharePoint library by adding the content type to the library. This enables data from the form to be submitted to the library as metadata associated with the submitted form. The form template is saved to a SharePoint library to ease permission management and provide version control.
Share this article:
Stumble This Delicious
Delicious
submit to reddit
Facebook
MySpace
MySpace

5 comments:

Tim said...

Is there a way to follow the same steps as above except pull from a sharepoint library where infopath form data has allready been submitted stored. It works fine with a list library but I cannot pull data from an existing infopath form library. I tried setting up the form library with different views e.g. data sheet, etc. but it still doesnt pull the data. Is there a work around...Help...(tim.welsh@gmail.com)

Daniel said...

Hi Tim,

There shouldn't be any reason that you can't select the form library when configuring the data connection. The fields in the main data source of your form, which are being promoted to the SharePoint list may not be selectable when configuring the data connection if you are publishing the form directly to the Form Library.

Firstly, make sure that the SharePoint site you connect to when configuring the data connection is the one with the Form library, not the root of the site collection.

You should then be able to select the form library from the lists and libraries on the site. When selecting the SharePoint columns for the data connection to retrieve data from, the fields in the InfoPath form which are "promoted" to the form library may not be visible. If this is the case, it is usually because you are publishing the form template directly to the Form Library and not via a Site Content Type.

To make the promoted fields of the Form Library available to select when configuring the data connection in the InfoPath form, you will need to Publish the form template to a Site Content Type (store the template somewhere accessible to users of the form).

You should then configure the Form Library to "Allow management of Content Types", and add the InfoPath Form content type created when publishing the form. You should set the new content type as the default for the library, remove the standard "Form" content type. If you already have forms in the library, you will need to set the content type associated with each to the new InfoPath form content type before you can remove the "Form" content type (If you don't do this, you will get a "Content type still in use" message when trying to remove it).

Once you have associated the InfoPath content type with the Form Library, you should have access to select the promoted fields when configuring the data connection. For example, if you have a custom field "Product Code" which is being promoted to the SharePoint Form Library, you will have access to select the field when configuring the data connection, which may not have been possible previously.

If you are using InfoPath 2007, there is an option when configuring the data connection to only retrieve data from the current item/form. If selected, the data connection will retrieve data from the selected columns for the current form only. If you are using an earlier version of InfoPath, you will need to a store unique identifier in the form's data source to be able to destinguish the current form from the rest.
The value of the field in the form would be used to find/filter items retrieved using the data connection to only show data from the current form.

If you are still having issues retrieving data from the Form Library you are submitting to, you can set up a CAML template to retrieve the data using the Lists Web Service on the SharePoint site. This is a more involved process, but is much more powerful as you have full control over the data which is retrieved.

InfoPath - Update Existing SharePoint List Item Programmatically Using CAML provides step by step instructions for setting up CAML (XML) templates to be submitted using a Web Service, but focuses on updating data in SharePoint as apposed to retrieving it. It should give you an idea of what is involved, but you will have to use an different method from the Lists web service, as the article focus on the UpdateListItems method.

Please let me know how you go, and if this was any help.

Daniel

Tim said...

Daniel,

Thanks for the detailed reply. I'm out of the country for a bit, but am looking forward to giving this a go when I return.

Regards,

-Tim

TA said...

I want to provide different decision. There is another alternative of InfoPath - it is free SharePoint based forms engine solution, which is called iTechnology Forms Accelerator. This product is very ambitious and its SharePoint integration provides the option to visualize your form version, simply by adding specific 'Form Version' Field, which is SharePoint field available in Data Model of this itfa forms engine. So...I think it is easier and different way. You may see the product's demo at iTechnology Forms Accelerator

drew said...

I have an issue with using Infopath setups in 2007 and company have now upgraded sharepoint to 2010 ... my question is can I still input and access data in libraries in sharepoint 2010...?using Infopath 2007...????

Post a Comment