HowTo:Use the HttpConnection Class to access a web service

From AgileApps Support Wiki

For:   Developers
Level: Advanced
Time: 20 minutes

See more:
    ◾ HowTo Guides

This example uses the HttpConnection Class to attach to an external web service.
It uses the Web Service HttpConnection code sample.

About the Example

In this example, the platform is configured to connect to an external domain using web services and retrieve data from the web service. The external domain in this example is

Specifically, the platform contains an application composed of two objects, Parts and Invoice, where the objects are related. Code in the Invoice object makes the HttpConnection request and retrieves the Parts information. See Configure the Platform for details.

Expected Outcome
When an invoice is entered (Add a Record), the platform will query the HelloWorldParts web service for a part number and populate a record in the Parts object.

Configure HelloWorldParts Webservice

  1. HelloWorldParts should expose their web service to receive request and response messages as XML
  2. A Servlet should be created that can receive request in XML and respond in XML format
    For Example, assume the following Servlet has been created on HelloWorldParts:
    Note that these are non-functional URLs for the purposes of this demonstration
  3. The platform connects to the HelloWorldParts webservice should just POST the XML-Request String using parameter name: Request

The XML Request format expected by HelloWorldParts :

User Name: USER
Password: HelloWorldParts
The part number in RequestXML is parsed by the servlet, which will return the Part field information in XML

Request and Response

Configure the HelloWorldParts servlet to accept the following Request and Response messages:

This is the Expected Response:

<?xml version="1.0"?>
   <part_description>SC 5000 3T/4S 2MB</part_description>
   <hold_name>Marketing Hold</hold_name>

Configure the Platform

The platform will contain two objects, defined with this relationship:

  • Invoice object includes a Subform based on the Parts object
  • A Rule is defined to:
  • Fire when a the Parts Grid in an Invoice Record is updated with a Part Number and Saved
Makes an HttpConnection request to the HelloWorldParts data base, retrieve the part data, and update the fields in the grid
  • Parts object has a Lookup field to the Invoice object

Create the Objects and Build the Relationship

To configure the platform, create the following objects, with fields defined as follows:

Invoice Object
Create the following fields in this object
Invoice Number
Part Number
Text Field, Maximum Storage Length = 50, Display Length = 30
Text Area, Width = 30, Height = 4
Choose Object Name = Parts
Parts Object
Create the following fields in this object
Part Number
Text Area, Width = 30, Height = 4
Parts Description
Text Area, Width = 30, Height = 4
Text Area, Width = 30, Height = 4
Text Area, Width = 30, Height = 4
Current Eco
Text Area, Width = 30, Height = 4
Pending Eco
Text Area, Width = 30, Height = 4
Text Area, Width = 30, Height = 4
Pending Revision
Text Area, Width = 30, Height = 4
Item Cost
Text Area, Width = 30, Height = 4

Add a Rule

  1. Create a class and a method for the Rule to execute.
  2. Copy this Code Sample into the method
  3. Create an Event Rule triggered by adding a record
  4. Add an action to the Rule that Invokes a Method
  5. Select the class and method you defined as the target of the Rule.

Try it Out

Verify that the action works as intended by activating the Rule from the platform:

  1. Open the Invoice object (appears as a tab in the application)
  2. Add a record and populate the grid with a valid part number
  3. Save the record

The expected result is that the grid is populated with data from HelloWorldParts, and that a Parts record is created (or updated) with detailed information