Table Save Action - Set Table Value In A Variable

Hi @snapcom

I think what you're looking for is companyAddressTable.changesetArray

The table stores pending edits in both the changesetArray and changesetObject properties, rather than the data property

You'll need to code your own implementation to "merge" the changes with the table's data, then set your variable to this new value

Example save handler script, assuming primary key is "id":

const data = [...companyAddressTable.data];

const new_data = companyAddressTable.changesetArray.reduce((previous, changeset_item) => {

  const item_index = previous.findIndex(item => item.id === changeset_item.id);

  const new_item = ({
    ...previous[item_index],
    ...changeset_item
  });

  return [
    ...previous.slice(0, item_index),
    new_item,
    ...previous.slice(item_index +1, previous.length)
  ]

}, data);

await setAddresses.setValue(new_data);

The only thing missing is that you'll also need to find a way to save these changes back to the query feeding data to the table, otherwise it will look like your changes are "undone" when the changeset is cleared after the save handler runs.

Hope this helps!

2 Likes