How to make bulk update on particular columns?

Hi,

I would like to make a bulk update on multiple selected rows on a primary key, unfortunately, the

{{ table1.recordUpdates }}

tries to updates all columns in the selected row. But the row contains also joined columns as well as a calculated column from the transformer.

I’ve tried something like this:

{{ 
var update = [];
table1.selectedRow.data.forEach(function(item, index) {
  update.push({ id: item.id, status: item.status, fulfillment_status: item.fulfillment_status });
}); 
}}

Unfortunately, it shows an error that’s not the correct syntax.

Hi @ckissi,

You’ll want to manipulate the .recordUpdates property using JS, my preferred method is doing it inside of the {{ }} tag in the bulk update. We have the lodash library built into retool, and their _.pick or _.omit methods are great for this. Pick grabs just the specified keys from an object, and Omit grabs all of the keys except for the specified one.

This is the example for a single object on Lodash’s docs:

var object = { 'a': 1, 'b': '2', 'c': 3 };
_.pick(object, ['a', 'c']);
// => { 'a': 1, 'c': 3 }

Here’s how I’d do it in Retool for recordUpdates, to grab just the name, age, and createdAt columns:
{{ table1.recordUpdates.map(row => _.pick(row, ["name","age","createdAt"]) ) }}

1 Like

@alex-w I've changed the code to:

{{ table1.recordUpdates.map(row => _.pick(row, ["id","status","fulfillment"]) ) }}

where id is the primary key in the table, the query runs without error unfortunately I cannot see any change in the table.

I've noticed that the value in the dropdown changes to the old (on its own) before the query is executed.

A few thoughts:
Can you confirm that the bulk update query is the one that is selected in the table’s bulk update action setting?

Does the query that loads data from the DB and populates the table run on success of the update query?

@alex-w

Yes, for both questions.

Do the changes get submitted to the database? After the Update_Orders query is run, what do the properties in the left panel of the editor look like?

@alex-w I've fixed it with omit.

{{ table1.recordUpdates.map(row => _.omit(row, ["shopify_id","shopify_order_name","created_at", "financtial_status", "line_items","picklist","returning_customer","checkbox"]) ) }}

Still don't know why the _pick didn't help.

image

No query is shown there. It's quite hard to debug. Maybe the possibility to show all executed queries in the interface or in the console.log would help.

Thank you.

1 Like

Hello folks!

While the logic of using the built in JS lodash library as mentioned in Alex's comment above to filter data from the table's state is still correct, the table's state property has been renamed from the previous table1.recordUpdates and has been split into several properties that can be used in various ways to access the row data of one or many selected rows to then filter out the data to pass into the bulk update query.

You now have access to much greater granularity and our docs on the table component includes a full list of all the properties, such as .selectedRows .changesetArray and .changesetObject will be very useful for most cases for passing into queries or filtering and saving to a variable first!