InfoPath – Setting Parameters on Web Service Calls when a form loads
When you have a secondary data source that uses a web service, InfoPath lets you specify the input parameters.
You can set the value here to any simple data type. However, it’s not immediately apparent how you would set the value to a variable data item. In this case I wanted to fetch some data for the currently logged in user. This data is then used to pre-populate the form.
InfoPath has a username() function. To use this to specify the value to the web service you need to create a rule for the Form.
1. Select Tools/Form Options.
2. Select Open and Save.
3. Click Rules.
4. Add a new rule.
5. Add an action to set a field value.
6. For the field, select your web service as the data source and the input parameter you want to set.
7. Set the value to a function or some other calculated value.
8. Add more actions if you have more input parameters.
9. Add a final rule to submit the query for the web service.
Ensure that the data connection for the web service has the “Automatically retrieve data when form is opened” option turned off.