4. Click OK to save the external item picker properties.
5. Publish the form to SharePoint to test. Preview mode won’t work because you are connecting to the external content type through SharePoint.
6. Click the Select External Item(s) button to confirm that a user can select an item from the external content type
The search items and display field in the Picker dialog depend on how the external content type was created and which filters were implemented on the finder method.
NOTE
Leverage External Data from a REST Web Service
Scenario/Problem: You need to present users with data from a REST web service.
Solution: Configure the REST web service data connection and use rules to change the parameters.
REST web services return XML documents and take parameters through the URL query string. If you need the parameters to be dynamic, they may be changed by using rules. This scenario steps through these processes.
First let’s create a connection to the REST web service:
1. In InfoPath Designer, select the Data ribbon bar. Click the From Web Service button and select From REST Web Service, as shown in Figure 9.54. The Data Connection Wizard appears.
2. In the Data Connection Wizard dialog, enter the URL of the web service along with the appropriate query parameters, as shown in Figure 9.56, to retrieve data based on the parameters.
This example uses a public REST web service from NOAA that is available through the Internet. You may use the same one to follow along: http://www.weather. gov/forecasts/xml/sample_products/browser_interface/ndfdXMLclient.php?zipCodeLi st=19115&product=time-series&begin=2010-05-27T00:00:00&end=2010-05-28T00: 00:00&maxt=maxt&mint=mint.
See http://www.weather.gov/forecasts/xml/rest.php for more information about available weather-based REST web services (or to copy and paste sample URLs into your form).
It is recommended to visit the site and grab the latest URL examples as these change, and you may experience difficulty entering the URL verbatim from this chapter. NOTE
3. Click Next. Enter a name for the data connection and click Finish.
4. From the Data ribbon bar, click the Show Fields button. The Fields Pane appears.
5. Switch the data source to the REST Web Service connection.
6. Drag the “data” group onto the form, as shown in Figure 9.55, to examine what data comes back from the web service.
FIGURE 9.54
Selecting the From REST Web Service allows you to create the appropriate data connection.
7. Preview the form to retrieve and display the data from the web service, as shown in Figure 9.56.
It looks like we only need the temperature information, which is returning the high and the low for the day based on the passed-in ZIP code. Therefore, remove all the sections on the form and drag over the temperature group such that we display only the infor- mation we need on the form. Optionally, remove the Time, Units, and Time Layout columns from the repeating table.
159 Leverage External Data from a REST Web Service
FIGURE 9.56
Previewing the form retrieves and displays the data from the web service.
FIGURE 9.55
Placing the data group onto your form allows you to examine the returned data from the web service.
Now let’s add some dynamics to the web service call. To do this, follow these steps:
1. Drag a drop-down list box (or list-based) control onto your form. Name the field City.
2. Connect the list box to a data source or enter values for example purposes. Because the web service takes in a ZIP code, you need the Value of the list box to be a ZIP code and the Display Name to be a city name. Figure 9.57 demon- strates manually entered values for the list.
FIGURE 9.57
Entering manual entries allows the list box to be populated with available ZIP codes / cities.
3. Select the City drop-down list and click Add Rule, This Field Changes, Query for Data.
4. Select the REST Web Service on the Rule Details dialog and click OK. The Rules pane appears on the screen.
5. In the Rules Pane select Add and select Change REST URL, as shown in Figure 9.58, to add an action that changes the URL parameters to the rule. The Rule Details dialog appears.
6. In the Rule pane, click the Function button. The resultant value for the URL needs to be a string. Therefore, we’ll use the concat function to construct a string using static text as well as the field value of City on the form.
7. Enter the concat function and use http://www.weather.gov/forecasts/xml/sample_ products/browser_interface/ndfdXMLclient.php?zipCodeList= for the first value.
161 Leverage External Data from a REST Web Service
8. For the second value, click the Insert Field or Group button and select the City field from the main data source. Because the rule is on the City drop-down list, the field is represented as a period (.) in the formula.
9. Remove the hard-coded ZIP code from the text and use the remaining portion of the URL for the third value in the concat() function (&product=time- series&begin=2010-05-27T00:00:00&end=2010-05-28T00:00:00&maxt=maxt& mint=mint). Your formula should look similar to Figure 9.59. Essentially, we are constructing a URL string using form values in place of hard-coded entries.
FIGURE 9.58
Adding a Change REST URL action allows the rule to change the URL parameters.
FIGURE 9.59
Using concat() constructs a URL string using form values.
Click Verify Formula to check your syntax! TIP
10. Click OK on the Insert Formula dialog.
11. Click OK on the Rule Details dialog.
12. In the Rules pane, click the drop-down menu on the Change REST URL action and select move up such that we change the URL first before querying the data source.
13. Preview the form to test the functionality. When the city is changed, the web service is queried and the new results are displayed.
Use the date functions to dynamically change the begin and end parameters in the URL example.
TIP
Don’t want anything to show in the table until a city is selected? Modify the REST web service data connection (Data ribbon bar, Data Connections button) and uncheck the Automatically Retrieve Data When Form Is Opened option.