Add new record in mysql depending of multi select values

Hi i got a multiselect component on my app like this

when i save that, in mysql should be created 2 records one for first option, one for the second, and both have the same product_id, how is that possible? should be like this in mysql


same product_id but diff location_id

thank you

You need to use a bulk insert query and pass it an array of records to insert. There are a few ways to make this array, but a Javascript transformer might be the most straigtforward.

This is probably pretty close to what you need.

// trMakeBulkInsertArray
lat newData = [];
let items =  {[myMultiselect.selectedItems}}
let product_id = 1
items.forEach(item => {
      product_id: product_id,
      location_id: item.location_id
return newData

Then in your bulk insert query use {{trMakeBulkInsertArray.value}} in the Array of records to insert property


Will try that, thank you

i tried that and query never ends

i also tried this using transformer in the same bulk insert query

what im doing wrong?

thank you

The first thing I see is trMakeBulkInsertArray is not a javascript transformer, it a javascript query.

Here is a post with some info on transformers and when you use them over queries:

Another thing to note, you can't put the code into the Transformer of the bulk insert query, that only executes after the query finishes running.


Yes that's my second example, I move the code as a javascript query

when i try to run the script

also i tried creating java script transformer

got it, my mistake now it works :stuck_out_tongue: thank you

1 Like