Creating Service Requests

Requires Platform 4.5+

Creating Service Requests

You use the serviceRequest or embeddedserviecRequest tags in your client UI file for your application to access enterprise data using Nexaweb's sql or web services type data services.

The following table provides a brief description of each of these tags: 

TagDescriptionWhen to Use
serviceRequestUses a dataRequestDefintion specified on the server-side to access enterprise data.
  • To define a data source on the server
  • To specify arguments
  • To use pre- or post-processors
  • To use parameter maps
embeddedServiceRequestSpecifies an sql statement or web services request in-line within the client UI file to access enterprise data.
  • To define a data source in the client UI file
  • To perform simple replacement with parameters
  • Note: You cannot use pre- and post-processors with an embeddedServiceRequest. To use pre- and post-processors, create a serviceRequest.

serviceRequest

The serviceRequest tag includes the attributes and child elements described in the following table:

ElementTypeDescriptionRequired/Optional
dataRequestIdAttributeSpecifies an ID to identify the dataRequestDefinition specified in the nexaweb-data.xml file to use to access enterprise data. The serviceResourceDefintion or serviceResourceReference in the dataRequestDefinition specifies or references the specific syntax of the sql statement or web services type request that accesses the data source.Required
idAttributeSpecifies an ID to identify this request.Required
onFailureAttributeSpecifies an MCO or Macro to run when the request fails.Optional
onSuccessAttributeSpecifies an MCO or Macro to run when the request succeeds.Optional
targetAttributeSpecifies an object to notify when the request completes.Optional
parametersChildSpecifies parameters for the data source.Optional

Example:

<serviceRequest dataRequestId="customerStateSearch" 
  id="getCustomerByState1">
  <parameters>
    <parameter name="state">{0}</parameter>
  <parameters>
</serviceRequest>

In this example, the serviceRequest, getCustomerByState1, uses the dataRequestDefintion, customerStateSearch, defined in the nexaweb-data.xml file to obtain data from the data source. customerStateSearch has argument mappings defined that allow getCustomerByState1 to pass the name of a specific state for which to obtain data.

embeddedserviceRequest

The embeddedserviceRequest tag includes the attributes and child elements described in the following table:

ElementTypeDescriptionRequired/Optional
idAttributeSpecifies an ID to identify this request.Required
onFailureAttributeSpecifies an MCO or Macro to run when the request fails.Optional
onSuccessAttributeSpecifies an MCO or Macro to run when the request succeeds.Optional
targetAttributeSpecifies an object to notify when the request completes.Optional
sql statement or web service requestN/ASpecifies the syntax of a an sql statement or web services REST or SOAP request.Required

Example:

<embeddedServiceRequest id="getCustomerByState2">
  <sqlSelect connectionId="corporate_db" 
    xmlns="http://nexaweb.com/service/data/sql">
    <table>customer_table</table>
    <where>state = {0}</where>
  </sqlSelect>
</embeddedServiceRequest> 

In this example, the embededServiceRequest, getCustomerByState2 uses the connectionID, corporate_db, defined in the nexaweb-sql namespace to execute a select satement that gets data from the customer table where state matches the specified value.

serviceRequest Expanded Example

The following example shows the use of a serviceRequest with the following criteria:

  • serviceRequest references a dataRequestDefinition (in the nexaweb-data.xml file)
  • dataRequestDefinition includes a serviceResourceReference that references a REST request (in nexaweb-webservice.xml file)

Client UI

  <data:documentDataSource xmlns:data="http://openxal.org/core/data" id="SearchResultsDS"/>
  <dr:serviceRequest id="FlickSrch" target="dataSource://SearchResultsDS"
   dataRequestId="FlickrSearchRest" xmlns:dr="http://nexaweb.com/service/data">
   <parameters>
    <parameter>{0}</parameter>
   </parameters>
  </dr:serviceRequest>

The client UI includes a dataSource, SearchResultsDS, to populate the UI with data as the result of an onCommand event (not shown). The SearchResultsDS dataSource obtains data from an external source through the data service serviceRequest, FlickrSrch. The FlickrSrch serviceRequest obtains data filtered by the argument passed to it from the external data source, FlickrSearchRest defined in the http://nexaweb.com/service/data namespace, the nexaweb.data.xml file.

Nexaweb-data.xml

<dataRequestDefinition id="FlickrSearchRest">
<serviceResourceReference dataServiceId="WebService" serviceResourceId="searchFlickrParam" />

The nexaweb-data.xml file defines the dataRequestDefinition, FlickrSearchRest, that references a WebService type data service request, searchFlickrParam, defined in the nexweb-webservice.xml file.

Nexaweb-webservice.xml

<webService xmlns="http://nexaweb.com/service/data/webservice">
<webServiceRequests>
 <restRequest id="searchFlickrParam">
   <url>http://www.flickr.com/services/rest</url>
 <urlParameters>
  <urlParameter name="method">flickr.photos.search</urlParameter>
  <urlParameter name="api_key">
    ffdbbd159bdde999cc638c280377a8d1
  </urlParameter>
  <urlParameter name="text">{0}</urlParameter>
  <urlParameter name="per_page">25</urlParameter>
 </urlParameters>
 </restRequest>
 </webServiceRequests>
</webService>

The FlickrSearchRest dataRequestDefinition in the nexaweb-data.xml file references the restRequest, searchFlickrParam, in the Nexaweb-webservice.xml file. searchFlickrPara invokes a GET to the URL, http://www.flickr.com/services/rest with the following additional parameters: method=flickr.photos.search; api_key=ffdbbd159bdde999cc638c280377a8d1; text=a user supplied value; per_page=25.

Putting it All Together

This client UI file also includes:

 <button text="Search Flickr" onCommand="serviceRequest:FlickSrch.execute(searchtext.text)"/>

When this onCommand event fires, the UI executes the FlickSrch serviceRequest. The serviceRequest executes and provides the data to the SearchResultsDS dataSource, through which the UI then displays the data in the UI with the following commands:

 <data:iterator xmlns:data="http://openxal.org/core/data" 
      dataSource="SearchResultsDS" name="rowIterator" 
      select="//rsp/photos/photo" type="ONE_WAY">
  <row>
     <cell text="{*('@title')}"/>
     <link alignHorizontal="right"
        onCommand="{bind(
        'select=.;dataSource=rowIterator;formatter=linkFormatter')}"
        text="View Picture"/>
  </row>
</data:iterator>