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
});
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.
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.