Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Populating form data from SharePoint List Views

Populating form data from SharePoint List Views

Rate This

The SharePoint list data connection in InfoPath is a great declarative way to bring in data from a SharePoint list, but it does have some limitations.  For those willing to put in a little extra effort, there’s much more that can be done with SharePoint lists: you can bind to views based on these lists. Here are the steps for creating the connection to a list view.

First, let’s get the URL:

1. Navigate to the SharePoint site that contains the list, for example:
http://contoso/sites/sales/Sales%20Contacts/Forms/AllItems.aspx
2. Go to “Modify settings and columns”
3. Copy the List={GUID} portion of the URL and paste this into a buffer like a Notepad window.
4. In Notepad, create the following URL (the blue portion us taken from the step 1 URL, and the red portion must be added.

http://contoso/sites/sales/_vti_bin/owssvr.dll?Cmd=Display&List={GUID}&XMLDATA=TRUE&noredirect=true

This will return an xml file that can be used in an XML file data connection, as if it came from a file system.  After this, you can use the URL as the location of an XML data file when creating a data connection.

 

Two caveats:
- Form users must have read access to the SharePoint list.
- During creation of the data connection, do not include the file in the form template, as it should be dynamically generated from the SharePoint list.

 

Some tricks:
1. When you’re in “Modify settings and columns,” if you click on one of the views in the list at the bottom, you should note that the URL is “enriched” with &View={ANOTHER_GUID}.  If you would prefer to use the columns from that view, you should similarly enhance the URL you use above.
2. You can also use the url to filter data rows based on column values. For example:

http://contoso/sites/sales/_vti_bin/owssvr.dll?Cmd=Display&List={115BC7B7-0A82-403E-9327-F3C73E6D37F3}&XMLDATA=TRUE&noredirect=true&FilterField1=xd__x007b_52AE1EF8_x002d_28E7_x002d_4CE4_x002d_AE23_x002d_54E23E80DDB5_x007d_&FilterValue1=Approved

Note: be sure to remove the “ows_” from the beginning of the FilterField ID.

 

With this filter, the XML file returned will be filtered to only display those projects that have been approved.  Without the green portion, you would see all the projects.

 

In order to populate other fields with data from WSS, you create the secondary data source just like above, then in form code or script, you can use GetDOM(“dataSource”) and walk the DOM normally, updating the main DOM as appropriate.

 

Ed Essey
Program Manager

Leave a Comment
  • Please add 1 and 1 and type the answer here:
  • Post
  • Hi Grahamp,

    Yes - you will need to hand-modify the View (the XSL file) that contains the control (i.e. the dropdown) that is showing the values.

    Take a look at the steps I provided to jccarvalho on Wednesday, April 15, 2009 11:27 - these are the same steps you will need to complete.

    Scott

  • How to connect to a XML file or SharePoint list sized at around 5500 records in browser-enabled Infopath form 2007

    Dear All,

    I have a data file which contains around 5500 records of user data. I created two data connections -one to very huge XML file and another to very huge SharePoint list. However both can't work in Browser form due to server timeout or what ever make the server can't response. Once I cut it 1/4 in size of records then it wokrs hence I guess this is due to too many records.

    I am wondering if there is anyway to connect to a single database file size @5500 records in browser-enabled InfoPath form? I don't have the SQL server.

    Please help!

    Regards,

    Ada

  • Hi Scott

    My previous posts are all working fine. Thanks a lot for the help.

    Would you know how I can populate a drop down box from a sharepoint list, or even a built in list, to return "active" hyperlinks. Or use a graphic, like a GO button once the item is selected from the drop down list.

    I only have 2 or 3 links per item which are intended to link to a procedure, form or word document which are all sitting in sharepoint library. Thanks

    Grahamp

  • Hi Grahamp,

    Here is something I just tested that, I think, is close to what you are asking:

    - Created  a list that contains a column of type "Hyperlink"

    - Added some items to the list where the hyperlink column points to different documents on my site

    - Added a Receive data connection from my InfoPath Form Template to this list and I am able to get the hyperlink column

    - Added a Dropdown Listbox control to the template, set the source to this data connection and then set the "Value" property for the dropdown to the hyperlink column and set the "Display" property to the Title column

    Now, when I select an item from the dropdown listbox what is being stored is the hyperlink to the document. What you cannot do "out of the box" is once an item is selected, automatically navigate to the selected link. You could use code for this or you could simply add a "hyperlink" control next to the dropdown listbox so once an item is selected, the hyerplink control will show the address and allow the user to click on the link.

    In testing this I found that the data connection retrieves both the "address" and "description" properties for the hyperlink. In my case, I left both of these as the URL so in the hyperlink control on the form template, instead of just pointing it to my field (i.e. field1) I needed to use the following expression so it would only display one URL:

    substring-before(my:field1, ",")

    I hope this helps!

    Scott

  • Thanks Scott

    The receive data connection works fine and the title of the document is displayed in the drop down box.

    I added the hyperlink control and edited it to select the data source (my:field1). With or without the substring the value returned is always, http://address/ and will not activate the hyperlink.

    Any ideas?

    Grahamp

  • Scott

    Update to my last post

    All works fine if I simply insert a hyperlink control using text. The problem occurs if I insert a graphic and then apply the hyperlink to read the field1 data source. The link simply reverts back to read the address field which is not populated. Thanks

    Grahamp

  • Hi Grahamp,

    What do you mean by "insert a graphic?" Can you provide me the steps you are following?

    Thanks,

    Scott

  • Hi Scott

    Sorry, I wasn't very clear.

    I'm using an image of a "GO" button in a cell next to the drop down list. The image is simply pasted into the cell and then I apply a hyperlink to the image that reads the value in the drop down list.

    Users select from the list and then the GO image to get the document.

    Hope this explains it better. Thanks

    Grahamp

  • Hi Grahamp,

    Hmmm...this is working for me. Here is what I have:

    - Data connection to my SharePoint list where I have a "hyperlink" field defined where each one points to documents on my site

    - Dropdown box that uses this data connection as its source. I have the "Value" property set to my hyperlink field and the "Display" property to the Title field

    - I copied and pasted an image to my form template and set the hyperlink as follows:

        - Link to: Datasouce: substring-before(my:field1, ",")

        - Display: This was auto-set to "<< Selection in document>>"

    Now, what may be key here is what is being returned from your list. Drag the node that the dropdown box is bound to your View again but this time as a text box. Preview the form and make a selection - is the correct URL being returned? Again, in my case I was getting the URL returned twice as: URL, URL - this is why I needed to use the "substring" function.

    Scott

  • Scott

    I checked the links and all are being returned correctly. Exactly as you described above I pasted an image and set the hyperlink to the Datasource.

    However before previewing I rechecked the hyperlink and find the "Link to: value has changed and the Adress is now selected displaying "http://address" with the Datasource greyed out.

    Totally confused?

    Grahamp

  • Hi Grahamp,

    Well on the positive side...at least we know why the link does not work! :)

    Let's look at something else: are you using the method described in this post to retrieve the fields from your list? If so, I was not - I was just using a standard SharePoint list data connection so I may need to try this method to see if there is any difference in the result. Also - how did you create the hyperlink column in SharePoint? Was it just adding a hyperlink column to your library or was it a site column? Can you provide me with a sample URL that you have in one of those fields?

    Scott

  • Scott

    Again like you I am using a standard Sharepoint list data connection, but will be using the method described in this post to filter the data when all is running.

    In the Drop down list box properties I have tried all 3 methods of linking the data source in the "List box entries" section all with the same result. The drop down works well and the correct data is returned. If I insert a hyperlink anywhere on the form view using the "Data source" as my:field1 and the "Display" as text all works perfectly well.

    Using an image and adding a hyperlink with a data source is where it falls apart.

    I have created a Links library in Sharepoint to handle the data required to be filtered and returned to various types of forms.

    Would you please look at entering the links manually in the drop down box, then paste and hyperlink an image to the drop down to see if you get the same result. Somehow I can't believe this is a Sharepoint issue.

    There's a 12 hour time difference between us so I'll follow with a sample url later if still required.

    Many thanks Scott

    Grahamp

  • Scott

    FYI I managed to find this link describing the same problem

    http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.infopath&tid=bb848d55-6ce1-4605-99bf-6a3ced937e31&cat=&lang=&cr=&sloc=&p=1

    Grahamp

  • Hi Grahamp,

    I read the post you found and have tried hard-coding the URL's in the dropdown as well as first hard-coding the hyperlink on the image and then switching back to binding the hyperlink to "field1" and in all cases, this is just working for me.

    I am still concerned though over the way you are phrasing what you asked me to do: "Would you please look at entering the links manually in the drop down box, then paste and hyperlink an image to the drop down to see if you get the same result".

    For this request, here is what I did:

    - Changed my dropdown box to "Enter list box entries manually"

    - I then entered two URL's to two different documents on my server. I set the "value" to the URL and the "Display" to some dummy text (here are my URL's: http://myservername/FileAttachments/SomeTextFile.txt and http://myservername/FileAttachments/SomeWordDoc.docx)

    - I had already pasted an image to my form in the following manner:

        - Navigated to C:\WINDOWS\Web

        - Right-clicked on the "exclam.gif" file and chose Copy

        - Right-clicked in my layout table cell and chose Paste (I have a layout table on my View with 1 row and 2 columns. The first column has the dropdown and then second column contains this pasted image)

    - I right-clicked on the image and chose Hyperlink

    - In the "Link To" option I chose Data Source and selected my "field1" and clicked OK

    I then Preview the form, select either option from the dropdown, click my image and the appropriate document opens.

    Is there anything here that is different than what you are doing?

    Scott

  • Hi Scott

    Aaaha it works but don't ask me why!

    The only thing that we are doing differently is that I am selecting Insert > Picture> From File and you are copying and pasting.

    Infopath will not let me paste a copied image from the clipboard onto the view, all options to cut, copy and paste are greyed out.

    When I copy an image already in my view and paste it into the required cell it works fine.

    So the operative word here is "paste" Any ideas why?

    Grahamp

Page 3 of 7 (105 items) 12345»