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

Instantly how to auto populate field in InfoPath based on another field? 2 steps process

No comments

Loading

In this “How to auto populate field in InfoPath” 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 that 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 the 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 with how to implement it. Here, for this requirement, we need to use the InfoPath data technique.

How to auto populate field in InfoPath based on another field (InfoPath Forms)?

Below is the step-by-step process of how to auto-populate fields in InfoPath form based on another field:

Step1: Create a secondary data connection to the custom list “Defects Tracking” – InfoPath query data from SharePoint list

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 on 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 the “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 all your relevant columns like Defect ID, Defect Details, and so on. Now the secondary data connection is ready.

Create two textbox columns, one to pass the input and 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 – InfoPath query data from SharePoint list

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 the 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 the Infopath form

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

Summary: How to auto populate field in InfoPath based on another field (InfoPath Forms)?

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. A 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: InfoPath forms tutorial

You may also like the below InfoPath forms tutorials:

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment