How to auto populate field in InfoPath based on another field?

How to auto populate field in InfoPath based on another field?

No comments

 18,769 total views,  90 views today

In this blog, I will share how to auto-populate the field in InfoPath based on another field. Let’s say I have a “Defect Tracking” custom list which has two columns “DefectID” and “Defect Details”. Now, the requirement is – in the InfoPath form there will be a textbox to enter the “Defect ID” and in another textbox “Defect Details” should be displayed which should filter the data from the “Defects Tracking” list.

Here, I will focus on the below two points:

  • How to add a data Connection to SharePoint List or Library in InfoPath Form.
  • How to query SharePoint list items using the Infopath data query.

 

Filter SharePoint List in InfoPath Form
Filter SharePoint List in Infopath Form

From the above list, if the user enters defect id in the form, then the corresponding defect details should display as a result in another textbox in the form.

Now, let’s start how to implement it. Here, for this requirement, we need to use the InfoPath data technique.

Step1: Create a secondary data connection to the custom list “Defects Tracking”

Click on the Manage Data Connection from the right side Fields panel.

Click on the “Add” button in the “Data Connections” wizard.

Create Secondary Data Connection in InfoPath Form
Create Secondary Data Connection in InfoPath Form

Then in the next screen, you will get an option as,

Create a new connection to:

  • Submit data – This is used to submit the InfoPath form data to the SharePoint list.
  • Receive data – This is used to read the data from the SharePoint list (by default, this will be selected).
Create Secondary Data Connection in InfoPath Form - Receive Data From SharePoint list
Create Secondary Data Connection in InfoPath Form – Receive Data From SharePoint list

As we want to display the data from the SharePoint list, we will go with the “Recieve” connection.

In the next screen, you will see “Select the source of your data”, select as SharePoint library or list.

Create Secondary Data Connection in InfoPath Form - SharePoint List or Library
Create Secondary Data Connection in InfoPath Form – SharePoint List or Library

Click on the Next button, you will see “SharePoint site details” screen.

Enter your SharePoint site URL in the “Enter the location of the SharePoint site” box.

Example:

http://servername:siteport/ or http://server/site
Create Secondary Data Connection in InfoPath Form - SharePoint Site Details
Create Secondary Data Connection in InfoPath Form – SharePoint Site Details

Then, in the next screen you will see the below message to select the list or library:

The SharePoint site that you selected has the following lists and libraries you can use as your data connection.

From the available lists or libraries, select your list.

Click on the Next button.

Select the list of columns you want to display from the “The SharePoint list has the following fields that you can select from.” screen.

Click on the Next ->Next->Finish button.

Summary about the above receive data connection:

Create a secondary data connection to your “Defects Tracking” list and while creating the data connection select “Receive data” from the SharePoint list. Then select your all your relevant column like Defect ID, Defect Details, and so on. Now the secondary data connection is ready.

Create two textbox columns, one to pass the input another one to display the result based on the input pass in the first text box (Defect ID), something like below:

  • SearchDefectByID
  • Defect Details

Step 2: query SharePoint list items using the Infopath data query.

Select the “Defect Details” text box in the form.

Step3:

Click on the Default value Fx button.

Step4:

Click on the insert field or Group

Step5:

Select your secondary data connection from the data connection list which you just created.

Step6:

Select the “Defect Details” from the Data Fields section

Step6:

Click on the filter button

Step7:

In the filter add select DefectID (from list secondary data connection) -eq "SearchDefectByID(from the form textbox - where you will enter that textbox).

Click 5 times OK, one after another.

Finally, the filter should look like below:

Defect_x0020_Details[DefectID = SearchDefectByID]

Demo screenshot:

Display infopath filed based on the other field
Display infopath filed based on the other field

Output – preview or runtime:

Filter SharePoint list items from Infopath form
Filter SharePoint list items from Infopath form

Now, we can see based on the value entered in the “SearchDefectByID” textbox, the corresponding defect details are displaying in the “Defect Details” textbox which is coming from SharePoint “Defects Tracking” list.

Summary:

Thus, in this blog, we have learned about how to filter the SharePoint list items using the secondary data connection data query and dynamically display the result in one textbox based on the value entered in another textbox. Few key points are:

  • How to add a data Connection to SharePoint List or Library in InfoPath Form.
  • How to query SharePoint list items using the Infopath data query.

See Also: