Query REST Webservices from InfoPath 2007 with qRules! - Jimmy Rishe
in

InfoPath Dev

Jimmy Rishe

Query REST Webservices from InfoPath 2007 with qRules!

It's now well known that InfoPath 2010 has the built-in ability to query REST webservices.  But did you know that you can use qRules' QueryData command to query REST data even if you or your users are still using InfoPath 2007?  Here's a simple example of how you can do this.

The below tutorial uses Yahoo's Geocode API as an example of a REST webservice to look up geographical detail using a zip code.  It assumes you are working with an InfoPath form that already has qRules 2.4 or higher injected into it.

  1. Open the data connection wizard to add a new data connection.
  2. Indicate that it is a connection to Receive data and click Next.
  3. Select XML document as the source for the data and click Next.
  4. Enter http://where.yahooapis.com/geocode?country=us&postal=10001 as the location for the data.  The objective here is to provide a valid URL that will return some data from which InfoPath can detect the structure of the returned XML. Click Next.
  5. Select Access the data from the specified location and click Next.
  6. Name the data source Zip Code Lookup, uncheck Automatically retrieve data when the form is opened, and click Finish.
  7. You should now have a new data source with a structure that looks like this:
  8. Now let's add a few controls to the form.  Add a new field called ZipCode to your main data source and create a textbox with this. Add a button underneath that and change its label to say Query.  Also, drag the City and State fields from the Zip Code Lookup data source and create textboxes or expression boxes with them.  These will display the data returned from the webservice.  Your form should look like something this when you are done:

  9. Now it's time to add the query logic.  Create a new rule on the Query button that does the following:
       Set the Command field in the QdabraRules data source to the value of the formula:
       concat("QueryData /dsname=Zip Code Lookup /url=http://where.yahooapis.com/geocode?country=us&postal=", ZipCode)
      

    Note that this formula constructs a URL to the Yahoo webservice, concatenating in a field value from the form for the zip code.
  10. Preview the form, enter a valid zip code in the textbox and click the Query button.  The query results should be displayed down below:

That's it!

Published Jan 04 2012, 06:04 PM by Jimmy
Filed under: , ,

Comments

No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.