I want to change only the data that is changeSet

Hello. I want to change only the data that is changeSet. However, if you actually make a query, you need to handle an exception as shown below. Is there any good way?

Hey @honoru!

The .recordUpdates property of your table should contain an array of all updated rows complete with edited and unedited data. If you're trying to only use the selected row you could do something like:

{{ mainTable.recordUpdates.find(record => record._id === mainTable.selectedRow.data._id) }}

Alternatively, I've used this in the past to pull in changes:

{{ { ...mainTable.selectedRow.data, ...mainTable.changeSet[mainTable.selectedRow.index] } }}

Both are pretty long though so you might also consider creating a standalone transformer to format your data before passing it to the mongo query, something like:

const recordToUpdate = mainTable.recordUpdates.find(record => record._id === mainTable.selectedRow.data._id);
const update = {
  $set: {
     document: jsonEditor1.value,
     type: recordToUpdate.type,
     screen: recordToUpdate.screen,
  }
}
return update;

Then you can reference {{yourTransformer.value}} in the update field.

Can you let me know if any of this is helpful?

@Kabirdas It was helpful for me! Thanks!

I've found it difficult to work with recordUpdates and changeSet as I couldn't find any docs about how these are structured and they are hard to inspect as their value empties quickly.

Ah, good callout @LeeIsles! We have some documentation here that describes each property, but, just in case anyone else stumbles across this thread here is a little illustration of the difference between the two. Given these changes:

recordUpdates looks like this:

  • it is an array
  • it contains all of the data from each row that has a change
  • its indexes do not map directly to the index of each row

changeSet looks like this:

  • it is an object
  • in contains only the data that has changed
  • its indexes match the data of each row

Hopefully that's a helpful illustration, let me know if there's anything that was of note to you that I missed!

Great! Thank you. I sort of didn't need the details after I read your first post as I could reverse engineer it and use in my code. Which worked great and was real life saver as I had been beating my head on that for longer than I should have. That said, it's great to have the details also.

As usual, nice work @Kabirdas and team Retool.

This is good, but I do need the details! I'm trying to figure out how to use GUI mode and chnagesetArray to update the MySQL database with just the changed data. What do I put in the "Filter by" and Changeset Key value pairs sections? This is all new to me so I really need it spelled out.