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