Using the ServiceAdapter to access a Business Entity to retrieve data from the client

The following sample code illustrates the use of the OERA ServiceAdapter to retrieve data using a BusinessEntity from the client in custom code (outside the SmartBusinessEntityAdapter). This might be used for loading any kind of control data, menu structures or data used for reports etc. from the backend to the client.  

In the first step we make sure the static dataset definition is included in the client side code. This is not required, but recommended for simplifying the writing of the client side code.  

The ServiceAdapter expects the following input parameters for the RetrieveData method:  


AppServer Partition:

Not required in our example, the ServiceAdapter will refer to the default AppServer partition

 BusinessEntity Name:

"Consultingwerk.SmartComponentsDemo.OERA.Sports2000.OrderBusinessEntity" in this example. This BusinessEntity is included in the CustomerExplorer sample application

 Request parameter object:

An instance of Consultingwerk.OERA.FetchDataRequest (or any object implementing the !IFetchDataRequest object)

  

The ServiceAdapter returns the Dataset as an OUTPUT PARAMETER DATASET or OUTPUT PARAMETER DATASET-HANDLE. In our example we are using the static dsOrder Dataset defined by the dsOrder.i Include file.  

The FetchDataRequest parameter object contains the parameters passed to the BusinessEntity and will be serialized to the backend. In our example we are using a constructor of the FetchDataRequest object that expects 3 parameters:  


TableName:

The name of the temp-table(s) to fill in the ProDataset (a comma-delimited list)

 QueryString:

A query string used to filter data in the database. The QueryString is expressed as a QueryString against the temp-table(s) and will be translated by the DataAccess object to a database query string. When concatenating fixed strings and parameters (the variable cSalesRep in this example) we recommend using the SUBSTITUTE and QUOTER functions.

 BatchSize:

The number of records to retrieve from the first temp-table (0 for all).

  

The ServiceAdapter instance can be accessed using a property in the Consultingwerk.Framework.FrameworkSettings static class.  

/* ProDataset definition for the Business Entity */
{Consultingwerk/SmartComponentsDemo/OERA/sports2000/dsOrder.i} .

DEFINE VARIABLE oRequest AS Consultingwerk.OERA.FetchDataRequest NO-UNDO .
DEFINE VARIABLE hContext AS HANDLE                               NO-UNDO .

oRequest = NEW Consultingwerk.OERA.FetchDataRequest 
              ("eOrder", 
               SUBSTITUTE("for each eOrder where eOrder.SalesRep = &1", QUOTER (cSalesRep)), 
               10) . 

Consultingwerk.Framework.FrameworkSettings:ServiceAdapter:RetrieveData 
              ("",
               "Consultingwerk.SmartComponentsDemo.OERA.Sports2000.OrderBusinessEntity",
               oRequest,                                                                        
               OUTPUT DATASET dsOrder BY-REFERENCE /* avoid deep copy */) .

FOR EACH eOrder:
    DISPLAY eOrder.OrderNum  eOrder.SalesRep eOrder.OrderDate.
END.