[Stackoverflow] [Progress OpenEdge ABL] JSDO assigning value to a field of a record in a table

Status
Not open for further replies.
N

NattWara

Guest
I'm stuck trying to assign a value to a field of a table in a progress database using javascript. The JS frontend communicate with the DB through "PAS OE" and the library I'm using in javascript is JSDO.

Progress Data Objects

I've read the documentation about the method assign() of JSDO but it wasn't very clear.

I'm able to query and display them fine. but i can't seem to assign a value to it.

I've read this very similar topic but it did not answer my question because other older project (using the same DB, different table) are working fine without changing anything in the back. So I not so sure if I should fix the data definition file in the server, or my code is just wrong.

Using the assign() method on the JSDO to update OE table information

So I'm using the code in those project as a base, but did some change to variable name.

My goal is that I will get a record with a specific id (will get 1 record, as the id is unique) then will update a field named "status" in that record to have a value of "No". Initially it value was "Yes".

Thanks in advance. Here's the code I'm using.


function updateStatus(id) {

var myTempTableInJS = alasql("SELECT * FROM ? xxqc_det_data WHERE xxqc_det_data.record_id='"+record_id+"'", [data]);
myTempTableInJS = myTempTableInJS[0];

return new Promise((resolve, reject) => {

if( myTempTableInJS === undefined || myTempTableInJS === "" ) {
reject();
}

var filter = "record_id ='" + myTempTableInJS.record_id + "'";

callRESTWebServiceWithCallback("DbData", "myDbTable", filter, (jsdo, success, request) => {

var table_ref = jsdo.temp_table;

table_ref.subscribe('afterUpdate', onAfterUpdate);

console.log(table_ref.getData()); //Data before change
console.log("before: "+ jsdo.hasChanges()); //this is false before assigning new data

table_ref.foreach(record => {
record.assign({status : "No"});
});

console.log(table_ref.getData()); //The data after change. But it still did not change. (Initially was "Yes", suppoosed to be "No" here but it's still "Yes")
console.log("changed: "+ jsdo.hasChanges()); //now this show as "true"

jsdo.autoApplyChanges = false;

jsdo.saveChanges(true).done(( jsdo, success, request ) => {

console.log("========== DONE ==========");

resolve();
}).fail(function( jsdo, success, request ) {

var lenErrors,
errors,
errorType;

errors = jsdo.temp_table.getErrors();
lenErrors = errors.length;

for (var idxError=0; idxError < lenErrors; idxError++) { // Each error
console.log(JSON.stringify(errors[idxError]));
}

reject();
});

function onAfterUpdate (jsdo, record, success, request) {

if( success ) {
record.acceptRowChanges();
} else {
record.rejectRowChanges();
}
}
});
}).catch(() => {

});
}

Continue reading...
 
Status
Not open for further replies.
Top