In this example, assume you want to call a web service and pass in a single parameter supplied by the user at runtime. You have a textbox on the form called wsParam1. You also have a drop down list which is populated using a secondary data source. You want to populate the drop down dynamically based on the entry made by the user in the textbox (or any other control for that matter) while the user is entering data into the form.
To start you create a new InfoPath project in Visual Studio. In the InfoPath IDE add a text box and a drop down list with the following properties:
Text Box |
Name |
wsParam1 |
Data Type |
Text (string) |
Drop-Down List Box |
Name |
field2 |
Data Type |
Text (string) |
List box entries |
Lookup values in a data connection to the database, Web service, file, or SharePoint library or list |
Click on the Add… button for the Drop-Down List Box Data Connection and follow the wizard. In the final step ensure that the Automatically retrieve data when form is opened checkbox is unchecked. Set the value and display name of the drop-down list box from the result set returned by the web service.
The stage is set and we’re ready to do some coding. We now need to use an event handler to call the web service when a user enters data into the text box. To access the event handler reopen the text box properties dialog.