The following sample code illustrates the use of the OERA ServiceAdapter to update data using a BusinessEntity from the client in custom code (outside the SmartBusinessEntityAdapter). Similar actions can be taken using the ServiceInterface when executing code already on the Backend.
When creating new records that should be submitted to the Business Entity for storing them in the database we do not need to retrieve data from the Backend first.
After loading the data from the OrderBusinessEntity (populating the dataset dsOrder) we are ready to update some values.
Consultingwerk.Util.DatasetHelper:SetTrackingChanges (DATASET dsOrder:HANDLE, TRUE) .
FOR EACH eOrder:
DISPLAY eOrder.OrderNum eOrder.SalesRep eOrder.OrderDate.
UPDATE eOrder.OrderDate eOrder.OrderStatus .
Consultingwerk.Util.DatasetHelper:SetTrackingChanges (DATASET dsOrder:HANDLE, FALSE) .
DEFINE VARIABLE hChanges AS HANDLE NO-UNDO. DEFINE VARIABLE cContext AS CHARACTER NO-UNDO. DEFINE VARIABLE cMessages AS CHARACTER NO-UNDO.
Before doing any modification (create, update, delete records) on the data contained in the Dataset, you must activate the TRACKING-CHANGES property on all tables of the Dataset. This can easily be achieved using the SetTrackingChanges method of the Consultingwerk.Util.DatasetHelper. After we are finished with the changes we need to set the TRACKING-CHANGES to false for all tables of the Dataset.
The GetChangesDataset method of the Consultingwerk.Util.DatasetHelper returns a new Dataset instance populated with only the changed records of the client Dataset. This reduced set of data is less expensive on the network and makes the execution of the following SubmitData method faster.
Now after submitting the data to the Backend we need to check for possible errors during the processing of the data. The Business Entity or Data Access class validation routines have stored possible validation messages in the ERROR-STRING property of the associated record buffers. The DatasetErrorStrings method of the ErrorHelper class is the simplest way to return all error messages contained in the Dataset.
A message starting with „errors:“ followed by all returned errors will be shown if there are errors returned after the call to SubmitData. The dataset is able to store errors per record so we might have multiple errors.
In case there were no errors after submitting the changes, the new values will be merged and accepted for the current dataset. This will end the roundtrip of the updated data and the change information will the wiped out.