Best way to mark a ProDataSet record as modified for SAVE-RO

Posted by bstaunton on 05-Apr-2018 03:41

Hi, I'm currently creating a REST interface, and I need a way to set a record as modified. I have a Create/PUT record section where I use 

DO WHILE queryh:GET-NEXT():
bufferh:MARK-ROW-STATE(3).
END.

And a Delete record section where I use

tableh:TRACKING-CHANGES = TRUE.
DO WHILE queryh:GET-NEXT():
bufferh:BUFFER-DELETE.
END.
tableh:TRACKING-CHANGES = FALSE.

But I'm having trouble finding a way to mimic a modification. Currently I'm using a query string parameter to delete the record from the primary index and putting a JSON string of the whole record in the body to create the record. But when I try to use MARK-ROW-STATE(2) I get an error that I need to attach a data source, which doesn't work as best as I can tell and causes problems anyway since this crosses the line between business entity and data access levels, or add a 2nd, before image, parameter which doesn't seem to work no matter what I do. Anyone have a good way of doing this?

Thanks,

bstaunton

Posted by Peter Judge on 05-Apr-2018 08:48

You can tell the MARK-ROW-STATE() where the before image should be.
 
def temp-table tt no-undo before-table bt
       field f1 as char.
def dataset ds for tt.     
 
create tt.
f1 = 'abc'.
 
temp-table tt:tracking-changes = yes.     
 
find first tt.
 
buffer tt:mark-row-state(row-modified, buffer tt:handle).
 
temp-table tt:tracking-changes = no.      
 
 
def var lc as longchar.
 
dataset ds:write-json('longchar', lc, true, ?,?,?,true).
 
message
string(lc)
view-as alert-box.
 
Shows
---------------------------
Message (Press HELP to view stack trace)
---------------------------
{"ds": {
  "prods:hasChanges": true,
  "tt": [
    {
      "prods:id": "tt2304",
      "prods:rowState": "modified",
      "f1": "abc"
    }
  ],
  "prods:before": {
    "tt": [
      {
        "prods:id": "tt2304",
        "prods:rowState": "modified",
        "f1": "abc"
      }
    ]
  }
}}
---------------------------
OK   Help  
---------------------------
 
 
 

All Replies

Posted by Peter Judge on 05-Apr-2018 08:48

You can tell the MARK-ROW-STATE() where the before image should be.
 
def temp-table tt no-undo before-table bt
       field f1 as char.
def dataset ds for tt.     
 
create tt.
f1 = 'abc'.
 
temp-table tt:tracking-changes = yes.     
 
find first tt.
 
buffer tt:mark-row-state(row-modified, buffer tt:handle).
 
temp-table tt:tracking-changes = no.      
 
 
def var lc as longchar.
 
dataset ds:write-json('longchar', lc, true, ?,?,?,true).
 
message
string(lc)
view-as alert-box.
 
Shows
---------------------------
Message (Press HELP to view stack trace)
---------------------------
{"ds": {
  "prods:hasChanges": true,
  "tt": [
    {
      "prods:id": "tt2304",
      "prods:rowState": "modified",
      "f1": "abc"
    }
  ],
  "prods:before": {
    "tt": [
      {
        "prods:id": "tt2304",
        "prods:rowState": "modified",
        "f1": "abc"
      }
    ]
  }
}}
---------------------------
OK   Help  
---------------------------
 
 

Posted by bstaunton on 10-Apr-2018 04:28

Thanks Peter Judge, this works in marking the row-state, though annoyingly SAVE-ROW-CHANGES doesn't save the new value to the database table.

This thread is closed