Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Submitting to a SharePoint List

Submitting to a SharePoint List

Rate This

As you know, submitting to a Microsoft Windows SharePoint form library from an InfoPath form is quite simple: just add a “submit” type of data connection to InfoPath and away you go. However, submitting to a SharePoint List is another matter. In this post, we will take a look at the steps necessary to enable this functionality.

Step 1: Create the list

1. Create a new custom list named: MyContacts
2. From the Settings button choose List Settings
3. Click Create Column
4. Add the following columns/data types:

  • FirstName, Single line of text
  • LastName, Single line of text
  • Email, Single line of text
  • Phone, Single line of text

The next step is to create a Collaborative Application Markup Language (CAML) template that contains the same XML nodes as the columns we added to our list – this will be used as a secondary data connection in the InfoPath Form Template.

Step 2: Create the CAML template

1. Launch Notepad (or any text editor)
2. Copy and paste the following code to the Notepad document:

<?xml version="1.0" encoding="UTF-8"?>
<Batch OnError="Continue">
    <Method ID="1" Cmd="New">
        <Field Name='Title'></Field>
        <Field Name="FirstName"></Field>
        <Field Name="LastName"></Field>
        <Field Name="Email"></Field>
        <Field Name="Phone"></Field>
    </Method>
</Batch>

3. Save this as: Add List Item Template.xml

 

Step 3: Create the InfoPath Form Template

1. Create a new, blank, browser-compatible form template
2. Add a “Receive” type secondary data connection to the Add List Item Template.xml file created in Step #2. (Make sure the options “Include the data as a resource file in the form template” and “Automatically retrieve data when the form is opened” are enabled.)
3. Add a “Receive” type secondary data connection to the “MyContacts” SharePoint List created in Step #1 and make sure the option “Automatically retrieve data when the form is opened” is enabled.
NOTE: Be sure to include the “Title” field along with the custom fields we created.

Each SharePoint list is created with a unique identifier called a GUID. In order to submit items to a SharePoint list, you must know the unique GUID for that list. These next steps will enable you to identify the GUID for your “MyContacts” list.

Step 4: Identify the list GUID

1. Open a browser and navigate to the MyContacts list
2. From the Settings menu choose List Settings
3. In the browser’s address bar you will see the URL appended with “List=”

 

4. Copy everything after the equals sign and paste this into a text editor as we will need this value later on.

NOTE: We will need the list GUID to be formatted as “{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}”. If your GUID appears as above with the hyphens and braces “escaped” (i.e. %7B for the braces and %2D for the hyphens) then you will need to replace the escaped characters with the braces and hyphens so when we use this GUID later, it will appear as: {1E76517B-2C36-4473-A420-A737D98589BC}

Step 5: Add controls to the InfoPath Form Template

1. Open the Data Source Task Pane
2. From the Data Source dropdown box choose the “MyContacts” connection

3. Right-click on “MyContacts” and choose Repeating Table – this will add a repeating table bound to that connection to your View
4. From the Data Source dropdown box choose Main
5. Add a text box to the “myFields” node named: ListName and set the Default Value property to the GUID value of your list – we will use this node to specify the list when we perform the Submit operation

 

To update the SharePoint list we will be using the “UpdateListItems” method of the SharePoint “lists.asmx” web service. This web method requires a couple of parameters (the list name and what gets updated) – now that we have added the “ListName” node which contains the GUID and we have the Add List Item Template XML data connection which describes our data structure we have all the necessary information to add the “UpdateListItems” web method!

Step 6: Add the “lists.asmx” web service

1. Add a new “Submit” type of web service data connection to the “lists.asmx” web service – this is typically located at: http://servername/_vti_bin/lists.asmx
2. Select the “UpdateListItems” operation
3. Double-click the “listname” parameter and assign the “my:ListName” node as the value

4. Double-click the “updates” parameter, select the “Add list Item Parameter” data source, select “Batch” and click OK
5. For the “Include” option select “XML subtree, including selected element”

6. Complete the Data Connection Wizard

Now that we have all the connections that are required, we now need to add the “submit” functionality to the form template.

Step 7: Add Submit functionality

1. Display the Data Source Task Pane
2. From the Data Source dropdown box choose the Add List Item Template data connection
3. Drill down through the data source, right-click on the Field node and choose Repeating Table

 

We need to change the text box control in the “Name” column to Read-only – if these values were to be changed it would affect the CAML and the submit would fail.
• Double-click on the text box in the Name column of the Repeating Table
• Select the Display tab
• Enable the Read-only property and click OK
• Add a new Button control to the View
• Double-click the button to display the Properties
• Click the Submit Options button
• Enable the option “Allow users to submit this form”
• Enable the option “Perform custom action using Rules” and click the Rules button
• Click the Add button
• Click the Add Action button
• From the Action dropdown box choose “Submit using a data connection”, select the “Web Service Submit” data connection and click OK
• Click the Add Action button
• From the Action dropdown box choose “Query using a data connection”, select the “MyContacts” data connection and click OK (this will automatically refresh the list in InfoPath so you can see the newly added record)

• Click OK until you are back to your form

NOTE: If you want to automatically clear out the submitted values, add another action to this Rule to “Set a field’s value” and the only option you need to specify is the “Field” option – select the “Field” node from the “Add List Item Template” data connection and then simply leave the Value option blank.

Step 8: Test!

1. Click the Preview button to preview the form
2. Fill in values for each of the fields: Title, First Name, Last Name, E-mail and Phone

3. Click the Submit button – the contact information should be submitted successfully and the “MyContacts” list automatically updated!

A special thanks to Matt Faus of InfoPathDev for for initially posting this solution!

Scott Heim
Support Engineer

Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
  • Hi Scott,

    Sorry for the slow response.

    When I right click on the repeating table in design and Repeating Table Properties the options for allowing users to add extra rows is dissabled. Is this down to the nature of the connection not allowing me to send multiple list entries at once?

    I created a new blank form through infopath.

    Thanks

  • Hi ClockeWork,

    Can you try these steps for me:

    - Launch InfoPath Designer

    - Choose the SharePoint List template type

    - Enter your SharePoint URL and click Next

    - Choose to create a new List...name it: ABCTest and click Next

    - Enable the option: "Manage multiple list items with this form" and click Finish

    - Right-click on the Repeating Section and choose Repeating Section properties

    Do you see the option: "Aloow users to insert and delete the sections" ?

    Scott

  • Hello. Thanks for this article.

    I think I'm getting hung up on one little aspect, if you could please help advise:

    I built my InfoPath form from an Access database. (So it has a data connection to an Access database).

    When I am creating the Submit function to my target list, i.e. Step 6, bullet #3...

    My version of the "ListName" comes up as "/dfs:myFields/my:ListName" AS OPPOSED to "my:myFields/my:ListName"

    Do you think this is what's holding me up? And what would you recommend doing?

    My InfoPath is not producing any error messages; it seems to work just fine... Except that no data is published to the List. It just says that it was submitted, and clears the data entry fields, but then nothing is added to the List.

    Thanks for your help.

    -Nate

  • Gentlemen,

    I found your post extremely helpful in teaching myself to create forms which will update Sharepoint Lists.  However, through no fault of your post, my forms failed to update the list.  My server is forscom2.bliss.army.mil, so I am using a secured Sharepoint site.  I followed all of the steps above exactly as typed and my form's submission was successful (meaning the infopath form responded that submission to the Sharepoint list was successful).  However, the data from the form did not populate the list.  What should I do?

  • CPT Ryan Rothschild,

    There are a number of reasons why your data may not be showing in your list. I know there are a lot of comments on this post but I would encourage you to go through them as I have addressed most all reasons. The other thing I would encourage, if you are not doing so, is to test the process with a test list where all columns are defined as "Single line of text."  These are the easiest to allow you to make sure your process works. For instance, if you have a column define as date and time, it must be formatted a certain way (which I cover in various comments on this post) or the data will simply not appear. So using just text columns to get the process working first is the easiest way. If nothing else, it rules out one of the reasons for failure.

    Scott

  • Hi Nate,

    Your issue (and my reply :)) is the same as what I posted for CPT Ryan Rothschild - take a look through the comments. The "XPATH" expression (dfs:myFields) will not impact this process unless you are not referencing the correct XPATH from your form template. Most likely it is due to one of the known causes that I have mentioned in prior comments.

    Scott

  • Thanks for your post. It works for simple text fields.

    BUT it does not work for User or Date type field.

  • Hi Sangeet,

    Actually it does work for those field types and others as well - you just have to make sure they are formatted the way SharePoint needs to receive the data. I know there are a lot of comments on this post but if you read through the comments there are steps on how to do what you need.

    Scott

  • Scott,

    I am experiencing the similar issue of submitting the form and it saying successful but no data shows.  I found in the sharepoint logs this message:

    High     Batchmgr Method error. Errorcode: 0x1dafa7d0. Error message: One or more field types are not installed properly. Go to the list settings page to delete these fields. bd199282-2854-4d89-b719-11b1c1d94b76

    I stepped down one by one removing fields I continue to get this message until all of the columns are gone.  I feel this is possibly related to the title column but no matter which ones I delete or in what order I still see this message. All of my columns are "single line of text"

    Do you anyone else on here possibly have an idea of where I might be going wrong.  The form will retrieve data from the list but wont write data.

    I read thru a lot of the comments with users experiencing this same issue but none posted anything about finding anything with there field types being wrong.

    Thank you

  • Scott,

    I figured it out but only with the help you provided to another post about 20 pages deep.   just for reference in 2010 you have to add a rule to get to the conditional formatting options.

    - Right-click on the Repeating Table used to add new items and select Conditional Formatting

    - Click Add

    - From the first box choose the field: Name

    - From the second box choose: is equal to

    - From the last box choose Type Test and enter: Title

    - Select Hide this control

    - Test!

    What this will do is prevent the Title field from showing in this repeating table. Now, you can submit items without a title but, by default, the title field shows in the list and a new item without a title shows: "No Title."

    This solved my problem.  Im still a little confused on how but im not that concerned with it.

  • Hi,

    I have slightly changed your instructions here, and the weird thing is that is works in the info path client (Preview Mode) and not in the browser.

    What I did was created a InfoPath from based on sharepoint List. For e.g. lets call this list List A.

    I customized the form for List A and want to add items from List A to List B.

    I created a new column on the Main (List A) in InfoPath and set its default value to the ID of List B and I set the web service up.

    Everything works ok, i.e I can submit the List A form and it submits items to List B using InfoPath (Preview Mode)... But in the Browser, I get the following error

    "An Error Occurred while trying to connect to a web service. An entry has been added to the windows log of the server"

    I cant put my finger on what is causing this, because it works ok when in the Preview Mode of InfoPath..

    Any Ideas?

    Thanks

  • 2. Select the “UpdateListItems” operation

    How? How? How?

  • Is there any way to only show the items the logged in user created on the current day?

  • Hi DG2g1,

    If you are using InfoPath 2010 or later, you can actually use the "queryFields" to add a filter to the data connection so it will only return those items that have been entered for the current day.

    Scott

  • Hi bronyx,

    On your SharePoint server, enable "Verbose" logging for InfoPath Forms Services. Then reproduce the error and check the ULS logs - you should get sufficient information to point you in the direction of the error.

    If you have a SharePoint farm that contains multiple web front ends, then chances are you are failing because of an authentication "hop" - meaning this: the InfoPath form was opened on Web Front End A - when the data connection was executed, it came back in through your load balancer which routed this request to Web Front End B - if that is the case, that is an NTLM authentication hop which is not allowed.

    But this is mere speculation until you get more details about the actual error.

    Scott

Page 30 of 36 (530 items) «2829303132»