Bulk Update Action Query?

Hi! can you share an example of what a bulk update action query should look like? I can't see much documentation?
@ak-ltree

It would be something like this:

You want to send an array of objects (corresponding to rows) where each object (row) has the primary key you want to update by as well as the fields you want to update for that particular row

Can I do this with an API call?

one per row?

Seems like it would be specific to your API (i.e. is your API set up to accept data in this format). Am I understanding correctly?

I don’t see the option for “bulk update” in an api call. what format would it expect? if my API isn’t designed for bulk updates, can I use a JS query to iterate over the rows and update? if so, how would I get the data?

You’d have to build out the API endpoint but it would probably look something like this

If you don’t have an endpoint to accept bulk items (e.g. an array of items with updated field values) then you can fire several API calls like this example: https://docs.tryretool.com/docs/scripting-retool#section-triggering-a-query-for-each-item-in-an-array

makes a lot of sense. what does the array come to me as?

So you can put anything in the Body of the POST request to your API, e.g { data: ARRAY_HERE } so it would look like the above. In the above example your api would receive a body with a .data field that has an array

How do I make the the array so that the number of elements (rows) is based on some inputs (in my case the number of rows selected in a table)?

If you have a table that enables multi-row select, then you can just do something like this … {{table1.selectedRow.data.map(i => i.first_name)}} to get a particular value from each selected row. If you want to construct the array from scratch you could do {{_.range(0, table1.selectedRow.data.length).map(i => ( { a: 'one', b: 'two'} ))}} and that would give you an array where each item was an object with an a and b field