Date: Fri, 29 Mar 2024 04:38:31 +0000 (UTC) Message-ID: <389043856.15.1711687111440@9e97ae5991e9> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_14_410834896.1711687111439" ------=_Part_14_410834896.1711687111439 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
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 al= ready on the Backend.
Before you can update existing data you need to load the data you plan t= o modify using the ServiceAdapter. This is similar to the requirement to FI= ND a record in the database before you can update it. The following wiki ar= ticle describes how you can use the ServiceAdapter to read data from a Busi= ness Entity http://jira.consultin= gwerkcloud.com:8090/display/SCL/Using+the+ServiceAdapter+to+access+a+Busine= ss+Entity+to+retrieve+data+from+the+client.
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 fr= om the Backend first.
After loading the data from the OrderBusinessEntity (populating the data= set dsOrder) we are ready to update some values.
Consul= tingwerk.Util.DatasetHelper:SetTrackingChanges (DATASET dsOrder:HANDLE, TRU= E) . =20 FOR EACH eOrder: =20 DISPLAY eOrder.OrderNum eOrder.SalesRep eOrder.OrderDate. =20 UPDATE eOrder.OrderDate eOrder.OrderStatus . =20 END. Consultingwerk.Util.DatasetHelper:SetTrackingChanges (DATASET dsOrder:HANDL= E, FALSE) . DEFINE VARIABLE hChanges AS HANDLE NO-UNDO. DEFINE VARIABLE cContext AS CHA= RACTER NO-UNDO. DEFINE VARIABLE cMessages AS CHARACTER NO-UNDO.
Before doing any modification (create, update, delete records) on the da= ta contained in the Dataset, you must activate the TRACKING-CHANGES propert= y on all tables of the Dataset. This can easily be achieved using the SetTr= ackingChanges method of the Consultingwerk.Util.Dataset= Helper. After we are finished with the changes we need to set the TRACK= ING-CHANGES to false for all tables of the Dataset.
The GetChangesDataset method of the Consultingwerk.Util.DatasetHelper re= turns 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.
hChang= es =3D Consultingwerk.Util.DatasetHelper:GetChangesDataset (DATASET dsOrder= :HANDLE) .
You can submit the changes to the Backend using the SubmitData method of= the Consultingwerk.Framework.FrameworkSettings:ServiceAdapter.
Consul= tingwerk.Framework.FrameworkSettings:ServiceAdapter:SubmitData ("", &nb= sp; = &nb= sp; = &nb= sp; "Consultingwerk.SmartComponentsDemo= .OERA.Sports2000.OrderBusinessEntity", &nb= sp; = &nb= sp; = &nb= sp; INPUT-OUTPUT DATASET-HANDLE hChange= s, &nb= sp; = &nb= sp; = &nb= sp; INPUT-OUTPUT cContext) . hChanges =3D Consultingwerk.Util.DatasetHelper:GetChangesDataset (DATASET d= sOrder:HANDLE) .
Now after submittin= g the data to the Backend we need to check for possible errors during the p= rocessing of the data. The Business Entity or Data Access class validation = routines have stored possible validation messages in the ERROR-STRING prope= rty of the associated record buffers. The DatasetErrorStrings method of the= ErrorHelper class is the simplest way to return all error messages contained in t= he Dataset.
A message starting = with =E2=80=9Eerrors:=E2=80=9C followed by all returned errors will be show= n 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.= p>
In case there were no errors after submitting the ch=
anges, 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.
cMessa= ges =3D Consultingwerk.Util.ErrorHelper:DatasetErrorStrings (hChanges) . IF cMessages > "" THEN MESSAGE "errors:" cMessages VIEW-AS ALERT-BOX. ELSE DO: hChanges:MERGE-CHANGES (DATASET dsOrder:HANDLE) . DATASET dsOrder:ACCEPT-CHANGES () . DELETE OBJECT hChanges . END.