1. Joe Hess
  2. PowerBuilder
  3. Tuesday, 30 March 2021 14:41 PM UTC

I have a local datawindow that could contain many rows, but only one row would be updated at a time. I'm looking for the best practice for updating the data.

Would I export just the new/changed row as a JSON and submit it to the web service? If so, how do I update the local datawindow row with the returned JSON so it reflects the correct content and state?

Would I export the entire contents? Upon return would I then reset the datawindow and load the returned JSON? This sounds expensive if there are many rows involved.

 

Thanks,

Joe

Accepted Answer
Mark Lee @Appeon Accepted Answer Pending Moderation
  1. Thursday, 1 April 2021 09:46 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Joe,

At present, the ImportRowAsJson() and ImportJson() methods are both for DataWindow to insert data, they don't do 'refresh' to the existing data in DataWindow.

It is suggested to work around it via doing the below.
After exporting the new/changed row as a JSON and submit it to the web service, manually remove the corresponding new/changed row in DW. When the web service updates the JSON data and responses back into the PB side, you should use the ImportRowAsJson() or ImportJson() method to import the response JSON data to the DataWindow.

Regards,

 

Comment
  1. Joe Hess
  2. Thursday, 1 April 2021 13:43 PM UTC
Thanks, Mark. This would probably work best with RowsDiscard().
  1. Helpful
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Thursday, 1 April 2021 12:32 PM UTC
  2. PowerBuilder
  3. # 1

I might be missing something here, but what exactly are you getting back from the web service that's different from what you have in your local dw?  From the scenario you described, it sounds like the data is sync'd originally, then you make changes locally and want to send those changes up via the web service.  Once the changes have been sent to the service, the data is back in sync right?  Then you would just need a ResetUpdate() on the local dw.  Are you worried about some individual rows working and some failing?  If you're getting some confirmation number and/or other data back, why not have a second dw for the results?  Then you can do dw.ImportJSON.

Comment
  1. Joe Hess
  2. Thursday, 1 April 2021 13:46 PM UTC
There may be some things happening on the backend with the business logic that changes the data. For invoices, I have an invoice number generator, address validation, and sales tax calculation. All three of those update the invoice in some way. I need to reflect those changes in the UI.
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 30 March 2021 16:26 PM UTC
  2. PowerBuilder
  3. # 2

You can use the ExportRowAsJson() and ImportRowAsJson() to move JSON in and out of DataWindows on a single row basis.

 

Comment
  1. mike S
  2. Tuesday, 30 March 2021 20:03 PM UTC
if you load it into a datastore, you would simply loop through the columns (use column number not name) to get/set the values in the datawindow. Check current datawindow value vs datastore value - if different then set it. if the same, then don't. that handles the status if you need/want that information in your datawindow.



i use this technique to build reselect row functionality for powerserver since PS doesn't support reselectrow. same idea, just using a webapi vs database select.
  1. Helpful
  1. Joe Hess
  2. Thursday, 1 April 2021 13:41 PM UTC
Mike, that's what I was thinking. I had hoped there was another way. Maybe the datawindow will have an UpdateJson() method someday. Thanks for the replies. Next beer is on me.
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Thursday, 1 April 2021 13:55 PM UTC
It does have Update JSON feature... the RESTClient does it for you and displays the data in the DW with a single line of code: https://docs.appeon.com/pb2019r3/powerscript_reference/ch02s04s820.html
  1. Helpful
There are no comments made yet.
Joe Hess Accepted Answer Pending Moderation
  1. Tuesday, 30 March 2021 15:42 PM UTC
  2. PowerBuilder
  3. # 3

Thanks, Mike.

How does that work with a web API? I'd have to send the data the web service as a JSON, but I need the state of the row to properly perform an insert/update/delete if using iDatastore. I'd have to manually change the state of the datastore to match the datawindow before exporting the data. In that case, I might as well export the row from the datawindow.

The main question is what to do when the response comes back with the updated row information. What is the best way to update the datawindow row to reflect the updated data and state. Do I have to update each column and the state manually? 

 

Joe

Comment
  1. Armeen Mazda @Appeon
  2. Tuesday, 30 March 2021 16:02 PM UTC
Hi Joe, The Web API is using the .NET DataStore or some other framework? https://www.appeon.com/products/dotnet-datastore
  1. Helpful
  1. Joe Hess
  2. Tuesday, 30 March 2021 16:29 PM UTC
Hi, Armeen.



My plan is to use the .NET datastore, but for this question, it should not matter. Maybe I don't understand how this is all supposed to work. I've consumed 100's of web services. I have not created one. For the ones I've consumed, I would send a JSON. The response would also be a JSON. I'm expecting this to be the same. I send a JSON of the data I need to update. The data gets validated in the web service. Some additional processing may take place like sales tax calculation or some kind of key generation.. Provided everything is valid, the database gets updated. The response would be a JSON containing the updated data (or an error message).



Once I get that response back into PowerBuilder, I need to update the datawindow so the user sees the updated data. What is the best way to update the row in the datawindow with the response from the API?



Thanks,

Joe
  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Tuesday, 30 March 2021 15:25 PM UTC
  2. PowerBuilder
  3. # 4

to process just the 1 row:

use a datastore and copy the 1 row (rowscopy) from the datawindow into that.  do your processing, then update the datawindow with the results

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.