SharePoint And InfoPath: Using Lookup Fields

This article explains how to solve the "InfoPath cannot submit the form because it contains errors" error in SharePoint.

SharePoint, InfoPath submit error, Lookup fields, saving data on Lookup Fields

While using SharePoint and InfoPath, one might encounter problems in saving the data on Lookup Fields. Here we can explore a solution to solve it.

The Problem

While using an InfoPath Form for a SharePoint 2010 List I encountered the following error:

SharePointInfoPath

The error is: InfoPath cannot submit the form because it contains errors.

Failed Solutions

I tried with the following approaches and failed:

  1. Manually created the field from InfoPath and assigned a Validation Rule. That failed since the validation rule was not enabled for the field.
  2. Removed mandatory check box for the field. That worked but the customer requires the field to be mandatory. Failed.

SharePointInfoPath

The following are the 2 lists included:

  1. Contracts list with Customer Name field and Product Code field pointing to Products list
  2. Products list with Code field

Concrete Solution

The following approach worked:

  1. Removed the field from SharePoint
  2. Created the field from InfoPath
  3. Used Choice field with multiple values
  4. Used Data Connections to Populate field value
  5. Published and Tested
  6. It worked

Procedure

The following is the procedure to implement the solution.

Step 1: Delete existing field

Delete the field from SharePoint. Save the changes.

Delete the field-row from InfoPath Form. Save the changes.

SharePointInfoPath

Step 2: Add Field from InfoPath

Create the field from InfoPath.

SharePointInfoPath

Choose "Actions" > "Add Field"

For Data type select "Choice (allow multiple selections)".

Choose "Mandatory" option.

Click the "OK" button to save the changes.

Step 3: Add the Field to the Form

Right-click and add a row to InfoPath form.

SharePointInfoPath

Drag and Drop the new field Product Code from the fields list to the form.

SharePointInfoPath

Step 4: Add Data Connection

Now the new field and control is missing data-population.

To add a data connection right-click the product code input-area and choose the "Properties" menu.

SharePointInfoPath

In the Properties box choose "Get choices from an external data source".

SharePointInfoPath

Click on the "Add" button to create the data source.

Choose the options as shown below.

SharePointInfoPath

SharePointInfoPath

Choose your SharePoint site as shown below.

SharePointInfoPath

Choose the Lookup List. (the secondary list from where data is pulled).

SharePointInfoPath

Choose the fields to display. (In our case only Code field exists.)

SharePointInfoPath

Enter the name for the data connection. (You may use the Suffix as DS.)

SharePointInfoPath

Click the "Finish" button to save the changes.

SharePointInfoPath

Step 5: Save and Publish

Click the "Save" button and Publish the form.

SharePointInfoPath

Step 6: Test the form

Test the form by adding a new item. You should see the item insertion has succeeded without any errors.

SharePointInfoPath

You can try with multiple-value checking and being displayed in the view mode too.

SharePointInfoPath

This concludes our solution to Lookup field error in InfoPath forms. I hope you enjoyed the solution.

References

http://bit.ly/10uiVpB

Summary

In this article we have explored a rare InfoPath scenario and the solution.