Check which records have been changed in JSDO

Posted by Kevin Thorne on 10-Mar-2017 06:28

In a multi-table JSDO foreach(), is it possible to determine which individual records have changes? 

jsdo.ttperson.foreach(function(personRecord) {

    console.log(personRecord.data.person_number);

// Do Something here if the record has changed

});

Posted by egarcia on 10-Mar-2017 08:45

Hello,

Yes, it is possible, however, we have not exposed this as an API in the JSDO.

Perhaps, we could add method or properties in the future to tell whether a record has been modified or if it is new.

You could try using the following approaches.

However, please notice that since they use undocumented or internal functionality, the code may changed in the future if we optimize or improve the internal structures.

1) Use jsdo.ttperson.getChanges() (or jsdo.getChanges() if you are using a single table dataset).

This function returns an array of objects with the record and a rowState property. This returns records for create, update and delete operations. (foreach() and getData() do not return deleted records.)

This function is not documented and the structure that it returns may changed in the future.

2) Check that a record has been modified by checking if it has a before-image.

You can use this approach in jsdo.ttperson.foreach().

(jsdo.eCustomer._beforeImage[customer.getId()] !== undefined)

Note: The before-image for a new record is null. The before-image for an updated / deleted record is the original record.

I hope this helps.

All Replies

Posted by egarcia on 10-Mar-2017 08:45

Hello,

Yes, it is possible, however, we have not exposed this as an API in the JSDO.

Perhaps, we could add method or properties in the future to tell whether a record has been modified or if it is new.

You could try using the following approaches.

However, please notice that since they use undocumented or internal functionality, the code may changed in the future if we optimize or improve the internal structures.

1) Use jsdo.ttperson.getChanges() (or jsdo.getChanges() if you are using a single table dataset).

This function returns an array of objects with the record and a rowState property. This returns records for create, update and delete operations. (foreach() and getData() do not return deleted records.)

This function is not documented and the structure that it returns may changed in the future.

2) Check that a record has been modified by checking if it has a before-image.

You can use this approach in jsdo.ttperson.foreach().

(jsdo.eCustomer._beforeImage[customer.getId()] !== undefined)

Note: The before-image for a new record is null. The before-image for an updated / deleted record is the original record.

I hope this helps.

This thread is closed