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:

  1. 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)
  2. Click the Rules button
  3. Click Add to add a rule
  4. Click Add Action
  5. For the Action, select Set a field’s Value
  6. For the Field, select the selectedAge node or whatever node you want to set automatically
  7. For the Value, click the Fx button
  8. In the Formula dialog, click Insert Field or Group
  9. In the Data Source dialog, select the secondary data source and then the age node or whatever node you want copy over
  10. Click the Filter button
  11. In the Filter dialog, set the filter to “secondary-data-source-ID is equal to main-data-source-ID”
  12. 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.