InfoPath 2010 - query using the REST interface
/
This is an exercise to play with the REST interface, which works extremely well with InfoPath 2010.
Scenario
- We have a postcode list. Filled with post codes and suburbs.
- In InfoPath, we want to select a post code and populate the corresponding data from the list.
- While this is possible using the old owssvr.dll trick, Let's do this one with the REST interface - which is a much cleaner example.
Steps
- Here's a very simple custom list, "Postcodes"
- The REST interface to select a row, using a filter:
http://spg-dev-jl/_vti_bin/listdata.svc/Postcodes?$filter=Code eq '2000' - This returns the following XML - you can see Title and Code in the XML
- Create an InfoPath 2010 form, create a few fields: "Postcode" (number) and "Suburb" (text, shown as expression)
- Create a secondary data source and connect to the earlier REST service.
- Add an action to Postcode - on change, set the REST URL, then execute the query.
The Change REST URL action appears when you have REST secondary data sources in your 2010 form.
We want to change the URL based on a formula, so set it to:
concat("http://spg-dev-jl/_vti_bin/listdata.svc/Postcodes?$filter=Code%20eq%20'", . ,"'")
- Finally, copy the new suburb back into our Suburb field from the updated secondary data source.
- The completed rule(s)
Result
Running in InfoPath rich client
Running in Form Server
Summary
- The REST data source is actually a FileQueryConnection and expects an XML result. In InfoPath 2010 though, we have the new action to "change" the path using rules which is really the unsung hero of this story.
- And thus we got to play with REST and InfoPath 2010