Auto-Fill from List Box
This came up on an internal mailing list:
We have a secondary data source that holds a list of entries; part of the data in the list - a name field - is used to populate the items in a listbox in the view. When the user selects an item in the list, I want the rest of the data from that entry to be used to populate the form's main data source.
Great scenario! It actually can be done with a combination of rules and filters (though I admit it’s not obvious), so you don’t have to write code for it.
For this example, I will assume you have a form with:
- A secondary data source with repeating items (for example, a list of people each with an ID, Name and Age)
- A dropdown that lists the values in the data source (e.g. displays the name of each person and uses the ID as the value)
- A set of nodes in your main data source that should be auto-populated when the dropdown changes (e.g. An age textbox that gets the age of the person selected in the dropdown)
What you’ll need to do is create a rule on the dropdown. The rule will set the value in the textbox by filtering the corresponding value in the secondary data source down to one that matches the dropdown selection.
Here’s how to do it:
- Double click the dropdown to open its Properties Dialog (it can be bound to a node in the main data source or in a secondary one, it doesn’t matter)
- Click the Rules button
- Click Add to add a rule
- Click Add Action
- For the Action, select Set a field’s Value
- For the Field, select the selectedAge node or whatever node you want to set automatically
- For the Value, click the Fx button
- In the Formula dialog, click Insert Field or Group
- In the Data Source dialog, select the secondary data source and then the age node or whatever node you want copy over
- Click the Filter button
- In the Filter dialog, set the filter to “secondary-data-source-ID is equal to main-data-source-ID”
- OK out of all dialogs, you’re done.
Note that if your dropdown is inside a repeating section/table, then you will need to manually adjust the value in the formula dialog after step 11 to use the “current()” function so the filter works correctly.
Comments
Anonymous
October 07, 2004
Hi!
I got the same problem and unfortunately my drop-down is inside a repeating section....
So, how do you actually use the "current()" function? Because I cannot find a way to do manual editing?
Thanks in advance...
RDAnonymous
October 08, 2004
To enter an expression manually, select "The expression" in the first drop-down of the filter building dialog (at step 11).
For more help on the current() function, look at the blog entry http://blogs.msdn.com/infopath/archive/2004/09/13/228881.aspx (September 13th)Anonymous
April 14, 2005
I like InfoPath, but was a bit reserved at first... and as a developer I have found InfoPath immensely...Anonymous
March 16, 2008
The comment has been removedAnonymous
March 22, 2008
The comment has been removedAnonymous
August 05, 2010
HI SIR, I AM SRINIVAS WORKING IN AVVAS INFOTECH, I WANT TO FILL THE DATA IN LIST COLUMNS AUTOMETICALLY BY USING THE ANOTHER LIST.. PLEASE GIVE ME A DETAILED EXPLANATIONAnonymous
June 29, 2011
So seriously -- how do I do this? "In the Filter dialog, set the filter to “secondary-data-source-ID is equal to main-data-source-ID” I am using infopath 2010 and have server issues like -1) when I double click a field I do not get its properties 2) In the properties window I can find there is no "Rules" button - the only rules button is on the Ribbon. Then of course the fact that the fiter dialog makes me pick fields. If I choose the option to have it let me enter an expression and enter "secondary-data-source-ID is equal to main-data-source-ID” EXACTLY as it is here minus the quotation marks it tells me I have an error.Anonymous
September 21, 2012
Is there any way to implement the Autofill for fields, like google search, using data from SQL table?