Populating Text Boxes Based Upon a Cascading Dropdown Boxes

K

Kevin McNeill

What I am trying to do is use a couple of cascading filtered drop down boxes
to populate some text boxes in a repeating section. The problem is when I
insert a new section and make a selection in the filtered drop down box the
text boxes are filled the first sections values regardless of the dropdown
box value. So basically it works fine until I try to insert a second section
then it fails. Both dropdown list boxes get their lookup values from the
Main Data source, which is an XML document. The text box fields are stored
in seperate fields but in the Main Data source.

I populte the text boxes by creating rules in the seocnd drop down box which
sets the textboxs equal to thier respective lookup values filtered by the two
dropdown boxes values. It works fine in the first section but when I add new
sections the second drop down box can be anything but it does not change the
values of the text boxes. It is like the filters in the rules don't see the
new vaule in the second drop down box.

Thanks
 
S

Scott L. Heim [MSFT]

Hi Kevin,

What you are seeing is expected behavior and discussed in this forum many
times - what you need to include is the "current()" function so you can get
the information from the "current" section you are working in. Here are
some sample steps that use the Microsoft Access Northwind sample database:

- Create a new, blank InfoPath form
- Add a data connection to the Northwind Customers table (you will only
need the CustomerID and CompanyName fields for this sample)
- Add a data connection to the Northwind Orders table (you will only need
the OrderID, CustomerID and Freight fields for this sample)
- Add a repeating section control to the form
- Add a drop-down box to the repeating section named: ddlCustomers
- Add another drop-down box to the repeating section named: ddlOrders
- Add a text box to the repeating section named: txtFreight
- Right-click on ddlCustomers and choose Properties
- In the List box entries section, choose: "Look up values in a data
connection to a database..."
- From the Data Connection box choose Customers
- Click the Select XPath button next to Entries, highlight d:Customers and
click OK
- Leave the Value field as CustomerID
- Click the Select XPath button next to Display name, highlight CompanyName
and click OK
- Right-click on ddlOrders and choose Properties
- In the List box entries section, choose: "Look up values in a data
connection to a database..."
- From the Data Connection box choose Orders
- Click the Select XPath button next to Entries, highlight d:Orders

** NOTE: The next steps are important for filtering the Orders to match the
selected customer! **

- Click the Filter Data button
- Click Add
- In the first box, select: CustomerID
- In the second box, select: is equal to
- In the third box, choose: Select a field or group
- From the Data Source box, choose Main
- Drill down, highlight ddlCustomers and click OK
- From the first box now, select The Expression - this will now show you
something like the following:

@CustomerID =
xdXDocument:get-DOM()/my:myFields/my:group1/my:group2/my:ddlCustomers

- Modify the expression so it looks like this:

@CustomerID = current()/my:ddlCustomers

- Click OK 4 times to get back to your form

** NOTE: The next steps are to set the txtFreight field based on the
selected order! **

- Right-click on ddlOrders and choose Properties
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box, choose Set a fields value
- Click the button next to Field, highlight txtFreight and click OK
- Click the "fx" button next to Value
- Click Insert Field or Group
- From the Data Source box choose Orders
- Drill down and highlight Freight
- Click the Filter Data button
- Click Add
- In the first box, select: OrderID
- In the second box, select: is equal to
- In the last box, choose: Select a field or group
- From the Data Source box choose Main
- Drill down, highlight ddlOrders and click OK
- In the first box, choose The expression - this will now show you
something like the following:

../@OrderID =
xdXDocument:get-DOM()/my:myFields/my:group1/my:group2/my:ddlOrders

- Modify the expression so it looks like this:

../@OrderID = current()/../my:ddlOrders

- Click OK 8 times to get back to your form

** NOTE: These last steps are to clear the OrderID's each time you select a
new customer! **

- Right-click on ddlCustomers and choose Properties
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box choose: Set a fields value
- Click the button next to Field, select ddlOrders and click OK
- Leave the Value field blank!
- Click OK 4 times to get back to your form
- Preview and test....after you select a customer, you should see just a
subset of the orders in ddlOrders. Once you make a selection from
ddlOrders, the freight amount should be populated in txtFreight.
- Insert a new item and repeat - you should be able to select a different
customer and order!

I know this is a long list of steps but hopefully it will help you to
understand where you will need to go in your solution.

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top