changesetObject no longer working as expected?

Hi all.

I just started learning retool. I was going through the tutorial (Retool apps tutorial: Interact with data) and it seems the changesetObject is no longer working as expected.

I was using last weekend and the following code snippet worked fine

{{table1.changesetObject['0'].id}}

However, now it is throwing up an error

TypeError: Cannot read properties of null (reading '0')

Did something change with changsetObject's implementation over the weekend?

Hi @tj11!

Welcome to the Retool community. Nothing changed with changesetObject's behavior over the weekend, but it will be null when no edits are present in the Table (which would be the case on a fresh page load). Are you seeing this error in the Debug Tools Console?

You can work around this by using optional chaining and nullish coalescing in JavaScript to provide a default value like so:

{{ table1.changesetObject?.['0'].id ?? '' }}

If you're still seeing this error after editing a cell in the id column, let me know!

Best,
Alexi

Hi @Alexi

I already made some edits to the table to make sure some data is present in the changesetObject. Despite that, I am seeing an error

ch1

ch2

Ok, I can see where the issue lies. There's no ID attribute in changesetObject if I don't edit the ID column itself.

But the documentation suggests that the ID column be used as the endpoint slug - Retool apps tutorial: Interact with data

I suppose the documentation is outdated. In any case, do you have suggestions on how to extract the row ID from the changesetObject so that I can send a patch query?

1 Like

Hi @tj11 It seems like you'll want to set your id column as the Primary key & then reference the changesetArray instead of changesetObject:

Would that work for your patch query?

2 Likes

Thanks a lot @Alexi and @Tess
Setting ID as the primary key and referencing the changesetArray fixed the issue :slight_smile:

Hi @tj11 Thank you! We also updated the docs to make this more clear moving forward :pray: