3.3.1 Client Processing
Executing a Server Routine (SrvRoutine) from a Web Page or Reusable Part is much the same as any remote procedure call.
In its simplest form, data can be returned directly to the fields and lists being displayed on the page by specifying them as the features to receive the data from the call to the SrvRoutine. Below, the SrvRoutine instance is defined and then immediately executed, with the returned data being mapped directly into a visual list component called #List.
Mthroutine Name(Load)
* Define the service instance and execute asynchronously
Define_Com Class(#ServerModule.GetEmployees) Name(#GetEmployees)
* Map the returned data directly into the list on the screen
#GetEmployees.ExecuteAsync( #List)
Endroutine
Notice that the command used to invoke the SrvRoutine is ExecuteAsync, indicating to execute asynchronously. This means the RDMLX in the Web Page or Reusable Part will continue running while waiting for data to be returned from the SrvRoutine. If you were to process #List immediately after the ExecuteAsync you may be processing an incomplete set of data.
While this style of coding is the least complicated it is not particularly robust. There is nothing to help protect the application in the event of a connection failure and typically you would not process the returned data until all the required data has been returned – to do so may cause unexpected results.
Extending this SrvRoutine, in the code below we put the returned data into an interim list and only process the list when we are notified that the SrvRoutine has completed. The Completed and Failed events have been added so that the application can monitor the server module processing and respond accordingly.
Def_List Name(#Employees) Fields(#Empno #Surname #Givename #Empthm …) Type(*working)
Mthroutine Name(Load)
* Define the service instance and execute asynchronously
Define_Com Class(#ServerModule.GetEmployees) Name(#GetEmployees)
#GetEmployees.ExecuteAsync( #Employees )
* When the server returns
Evtroutine Handling(#GetEmployees.Completed)
* Load the list data
Selectlist Named(#Employees)
Add_Entry To_List(#List)
Endselect
Endroutine
* If the server call failed
Evtroutine Handling(#GetEmployees.Failed)
* Error handling
Endroutine
Endroutine
Note: Lists can be returned into either a working list, as in this example, or a UDC.
For more information on calls to Server Modules refer to Asynchronous vs Synchronous Database Access.