Write/Read text area to DB line by line

Ooohh, I do see the use case then! Clever even.

I am guessing at your field and table names here.

You need to take the .value from the text box and split creating an array, but make it an object array: How to Split a String by Newline in JavaScript | bobbyhadz

Then you need to take the array and convert it into an object array with the key name being the column name for the household code: Javascript: Whats the best way Convert Array into Object? - Stack Overflow

Now you need to add your campaign_id to the object array. Now you have an object array that can be passed to a bulk insert query. Here are some tips on creating that array and using the query: How do I add multiple rows to table in PostgreSQL? you can find more tips on the forum.

Now to get the data back from the table into the text box, you are going to query the household table using {{tblCampaigns.selectedRow.data.campaign_id}} as a filter. Add a transformer that does a join, something like return {{data}}.household_ids.join("\r\n"); and then set the default value of your text box to the query data.

If you need to also do updates then use a bulk upsert instead of bulk insert. If you need to do deletes, well, that is a whole 'nother ball of wax.

1 Like