Know which table field was edited

Hi,

When I batch update rows by id from a table, is it possible to capture in javascript for each row which of the fields where actually changed?

How about comparing .data with .recordUpdates ? With a bit of logic, that should give you the exact field that changed

Hi :wave: @minijohn has a great suggestion here! You can reference .recordUpdates to get an array of all the rows where any edits were made with all fields in that row (both edited and unedited).

You can also reference .changeSet to get an object of only the values that were changed and the indices of their row in the table.

I hope you can use either of these or a combination of both fields for your use case :slightly_smiling_face:

Thanks for these suggestions. I'm going to paste my code here, because there were some things to figure out. Especially that .data is an object and .recordUpdates is an array.

This run script is in the success handler of a batchUpdate query when the table is saved. It loops through each recordUpdate and searches in the original data the row with the same id. Then it checks if a specific field was changed. It then runs another query for each updates row by passing the id in the additionalScope object.

Contracts.recordUpdates.forEach(sendSignedNotification) 

function sendSignedNotification(item) {
   const originalData =  formatDataAsArray(Contracts.data).find(({id}) => id === item.id)

   if(originalData.signed != item.signed && item.signed == 1) {
      runNotificationFlow.trigger({additionalScope: { contract_id: item.id}})
   } 
}