About me

Calendar

Search

Recent Articles

Recent Comments

Links

Statistics

Support


Except where otherwise noted, this site is licensed under a Creative Commons License.
除特别说明,本站所有内容都遵循创作共用协议.

About ADS

 

 
给我留言My Guestbook  我的照片My Photo  友情提示您,当前时间为:

Automatically Populate Fields from a Drop-Down Selection

[ 2007/6/5 8:28:00 | ]

This tips for InfoPath is from this site:

http://www.infopathdev.com/blogs/matt/archive/2006/04/18/Automatically-Populate-Fields-from-a-Drop_2D00_Down-Selection.aspx

The full artical:

Matt Faus

Automatically Populate Fields from a Drop-Down Selection

When creating a form that deals with data that has already been collected and stored it is very convenient to have a drop-down menu that will populate several other fields whenever a selection is made. One such example of this would be a form used for shipping items to clients. If shipment information has already been input and saved a drop-down that allows all of the information to be automatically recalled is very helpful in filling out the form every time thereafter.

In this task we will create a secondary data source that contains information about a list of clients and then enable a drop-down menu listing these clients to populate several other fields on the view. First, let’s make the secondary data source.

Create the secondary data source:

Copy the following XML text into a text editor, and then save the file as Clients.xml.

<?xml version="1.0" encoding="UTF-8"?>
<ClientInfo>
    <Clients>
        <Client>
            <ID>1</ID>
            <Name>JT Flights</Name>
            <Address1>2200 University Drive</Address1>
            <Address2>Suite 110</Address2>
            <City>New York</City>
            <State>New York</State>
        </Client>
        <Client>
        <ID>2</ID>
            <Name>Northern Lights Advertising</Name>
            <Address1>1234 Grand Way</Address1>
            <Address2></Address2>
            <City>Plano</City>
            <State>Texas</State>
        </Client>
        <Client>
        <ID>3</ID>
            <Name>On Target Sales Consulting</Name>
            <Address1>1704 S 108th Avenue</Address1>
            <Address2>Suite 213</Address2>
            <City>Seattle</City>
            <State>Washington</State>
        </Client>
        <Client>
        <ID>4</ID>
            <Name>Plush Designs</Name>
            <Address1>6099 Main Street</Address1>
            <Address2>Building 2</Address2>
            <City>Panama City</City>
            <State>Florida</State>
        </Client>
    </Clients>
</ClientInfo>

Add the secondary data source to the form template as a data connection:

  1. Design a new blank form.
  2. Choose Data Connections from the Tools menu, and then click Add.
  3. In the Data Connection Wizard, select Receive Data, and then click Next.
  4. Select XML Document, and then click Next.
  5. Click Browse, locate and select the Clients.xml file, click Open, and then click Next.
  6. Click Finish, click Yes, and then click Close.

Design the form:

  1. From the Layout task pane insert a custom table with 2 columns and 10 rows.
  2. From the Controls task pane add a drop-down list box to the first column of the first row.
  3. Add text box controls to the third, fifth, sixth, eighth, and tenth rows of the second column.
  4. Type the labels Name, Address, City, and State to match Figure 1.


Figure 1. The form design.

Revise the schema:

As you were adding controls in the previous section you might have noticed that InfoPath was automatically generating nodes in the schema to map these new controls to. Instead of the generated names that InfoPath gives these nodes, we want to rename them to make them easier to understand.

  1. Open the Data Source task pane, double-click the field1 node, and then change the name to ClientID.
  2. Click OK.
  3. Repeat steps 1 and 2 to change the names of the nodes according to the following mapping:
    1. field2 = Name
    2. field3 = Address1
    3. field4 = Address2
    4. field5 = City
    5. fiedl6 = State


Figure 2. The data source.

Fill the drop-down list with values from the secondary data source and add rules:

  1. Double-click the drop-down list in the view.
  2. In the Data Source section select Look Up Values From Data Connection, select Clients from the Data Connection drop-down list, and then click the XPath button to the right of the Entries field.
  3. From the dialog box that appears choose /ClientInfo/Clients/Client, and then click OK.
  4. Click the XPath button to the right of Display Name, select Name as the value to display, and then click OK.
  5. Click Apply, and then click Rules.
  6. Click Add, name the new rule Set Name, and then click Add Action.
  7. Select Set A Field’s Value from the action drop-down list, and then click the XPath button to the right of Field.
  8. Select /my:myFields/my:Name from the list, and then click OK.
  9. Click the formula button to the right of Value, click Insert Field Or Group, select Clients (Secondary) from the Data Source drop-down, select /ClientInfo/Clients/Client/Name in the list, and then click OK.
  10. Select the option to Edit XPath (advanced), modify the XPath by appending an XSL conditional statement at the end to match the following example.

xdXDocument:GetDOM("Clients")/ClientInfo/Clients/Client/Name[../ID = current()]

  1. Click OK three times.
  2. Repeat steps 6 through 11, while substituting the appropriate nodes, for the Address, City, and State fields.


Figure 3. Filling the drop-down list with options from the secondary data source.


Figure 4. Adding the rules to the drop-down list control.

Try it:

  1. Click Preview Form (or press ALT+P on the keyboard)
  2. Make a selection from the drop-down list on the right.
  3. Notice how all of the fields are automatically populated from the secondary data connection.


Figure 5. Using the form.

Published Tuesday, April 18, 2006 10:45 AM by Matt Faus
Filed under: ,

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Some comments from Karibu:

1. for Access datebase, the XSL condition statement shall be like (the @ID is the dropdown list value):

   [../@ID = current()]

2. When you creating the Action for Rules, after click the formula button to the right of Value and Insert Field Or Group, use the Filter can also do the job.


发表评论:

    昵称:
    密码:
    主页:
    标题:
  • 本博客文章由karibu提供
  • 本博客内部所有文章如需转载,请联系原作者或转载前作者