Changing look up values from script

P

Paul Robinson

Hello everyone,

I'm having a lot of fun designing a questionaire in SP1. One of the
questions is proving a little tricky however. I have a list of world regions
in a drop down box (linked to an XML resource file). When the user picks a
region, I want to populate another drop down with the contries in that region
(again from a different group in the XML resource file).

Currently to do this I've got a number of fields/drop downs containing the
countries and i'm using rules to show/hide the country fields based on the
value in the region field.

Obviously I'd rather create an OnAfterChange event on the region field and
change the possible list of countries selected from a single country field/
drop down.

Any idea how I might accomplish this?
 
S

Scott L. Heim [MSFT]

Hi Paul,

If the data in your XML Resource Files is "related" in some way, you could
use filters in the same way you would filter data coming from related
database tables.

What you are asking about is "cascading" or "synchronized" drop-down lists
and this is highly used functionality but in order for this to work as you
need, the data needs to be "related" in some manner.

Here are some sample steps and sample XML files so you can see how this may
work:

** XML Files:

- CompanyList XML file:
<?xml version="1.0" encoding="UTF-8"?>
<company>
<companyName>A</companyName>
<companyName>B</companyName>
<companyName>C</companyName>
</company>

- CompanyList_Orders XML file:
<?xml version="1.0" encoding="UTF-8"?>
<companyOrders>
<companyOrder>
<companyName>A</companyName>
<orderID>1</orderID>
</companyOrder>
<companyOrder>
<companyName>B</companyName>
<orderID>2</orderID>
</companyOrder>
</companyOrders>

** InfoPath form
- Create a new, blank InfoPath form
- Add a drop-down list named: ddlCompanies
- Add a drop-down list named: ddlOrders
- Add a "Receive" data connection to the CompanyList XML file
- Add a "Receive" data connection to the CompanyList_Orders XML file
- Right-click on ddlCompanies and choose Properties
- In the List box entries section, select the option "Look up values in a
data connection to a database..."
- In the Data Connection box select CompanyList
- Click the button next to Entries highlight CompanyName and click OK
- Leave the Value and Display name fields as they appear and click OK
- Right-click on ddlOrders and choose Properties
- In the List box entries section, select the option "Look up values in a
data connection to a database..."
- In the Data Connection box select CompanyList_Orders

** NOTE: Important steps for filtering data! **

- Click the button next to Entries and highlight CompanyOrder
- Click the Filter Data button
- Click Add
- In the first box select CompanyName
- 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
- Highlight ddlCompanies and click OK
- Click OK 3 times to get back to the Properties screen
- Click the button next to the Value field, highlight OrderID and click OK
- Click the button next to the Display name field, highlight OrderID and
click OK
- Click OK

** NOTE: Important steps to clear the ddlOrders list each time a selection
is made **

- Right-click on ddlCompanies and choose Properties
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box choose "Set a field's 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 the form - make a selection from the customer list and you should
only see the orders related to that customer!

I hope all of this helps!

Scott L. Heim
Microsoft Developer Support

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

Paul Robinson

Thanks Scott that is exactly what I need to do. The data in my XML file can
be restructured so it is related, since it concerns regions of the world and
countries in each region.

And a fast reply too. Superb, very impressed. Thanks.
 
S

Scott L. Heim [MSFT]

Hi Paul,

Thanks! I am glad the information helped.

Take care,

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