Manually updating changesetArray for bulk updates

I have a table with an editable column and I'd like to push bulk updates across multiple rows. I can't seem to find a way to set changesetArray with new values from a javascript query. Does anybody have an idea how to do this?

1 Like

Hi Eric,

Are you trying something like this after a change?

Yes, sort of? I want to manually add new objects in bulk to the changesetArray. let's say I have a column called "activated". And let's say I have another data source that would allow me to update that column in the table and let the user preview it before applying the changeset.

I would want to say table1.changesetArray = newChangesetArray

I don't get it exactly, but in the query, you can use Object.assign()

const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);

console.log(target);
// Expected output: Object { a: 1, b: 4, c: 5 }

console.log(returnedTarget === target);
// Expected output: true

AFAIK, you cannot alter the changesetArray at all (there is no public set function for this property).

You would have to transform and return the whole set of data and use the results for your review table and then use that table to drive the bulk updates.

Yeah, this is what I suspected. There's no "set" function for the changesetArray. I guess I would have to write some kind of query or transformer to sit inbetween the database and the table. it would be nice to be able to update the changeset and then "save" those changes.

1 Like

I am with you. Updating the changeSet programmatically instead of updating the table source and reloading (which can be "expensive") has been requested a few times before but there is no clue if this has ever made it to the roadmap or not.
If a Retooler could chime in...

1 Like

Hello @Eric_McGregor , @yiga2 ,

There is currently no way to update the changeSetArray programmatically built in Retool. I have gone ahead and created a Feature Request in our logs as I can see the value as well.

-Brett

4 Likes

My use case is to give the user a preview

for example, i have a function that copies data from a table and user can paste it to another, so my idea is to set the copied data as a ChangesetArray, that way the user can preview the changes that will be made

I have a use case for this as well: I'd like to create a way to programatically fill a column with the last changed value in that column. I can not achieve this using a query since I'd need to dynamically set the column. Disabling prepared statements entirely for our RetoolDB instance is way too excessive to be able to support this one use-case.

P.s. off-topic but being able to disable prepared statements on the query level would be an even better solution.

"disable prepared statements on the query level"

Hey, I think you CAN do this. Go to your query resource under 'resources'. look at the settings. there's a checkbox for "Disable converting queries to prepared statements".

I'm fairly new to Retool, but from what I can see, "Resources" are thing like Database connections and API connections, right?

If I go to the code tab, find my query and look under "advanced", I don't see an option "Disable converting queries to prepared statements". I can only find that as a setting for my DB Connection, which would mean it wouldn't be on the query level, but rather on the db connection level, which is way to broad for us.

Please let me know if I'm missing something!

I also have a use case for this. I have a table which stores a backend value in Cents. In retool, I want to display it dollars and allow the user to edit the value as a retool Currency. Retool Currency does not play nice with the backend stored as cents, so I need to multiply the user value by 100 in order to save it to my database properly.

This feature would be useful to me as well

+1 to this request

1 Like

Thanks for bumping this, @Micael_Batista and @JosephAmato! It helps us to prioritize the ongoing development of Retool as a product. :slightly_smiling_face:

Adding another +1 for this functionality

1 Like

I sort of do this(not really) but I avoid the expensive reload of the table data. When my table data loads, it gets pushed into a state variable and my table references the variable not the query. I change some table data and then a script runs and collects all the items that need to be changed as well in bulk. I then process the items accordingly and bulk update the database. On success of the database update, I then setIn() the variable with the values, reset the table change set() and I get to skip pulling back the updated data from the database.

3 Likes

Thanks for sharing, @Shawn_Crocker! That's generally the workaround that I suggest, as well. The one drawback is that it isn't obvious to the user which cells in the table are in sync with the database and which have been edited.

1 Like

That is true. But, I think the user is generally under the assumption the data is in sync and probably isn't giving it any thought. And, if the data in the database is the same as the data in the variable, I feel like that's basically in sync. In my case, I also have an on failure condition setup on the database update query that also clears the changeSet so the user sees there value get reset.

2 Likes