Trigger in Bulk insert

Hey,

  • Goal: I am trying to implement a bulk insert operation. The insert operation itself works; however, the filter logic intended to check if the data already exists in the database does not function as expected. I need the bulk insert to exclude records that match certain conditions against existing database entries.

  • Steps: I tried different filter syntax as well as using a normal insert a sql code with insert.

  • Details: My code:

  • {{
    listView2.data.filter(item => ((item.switch2 === true || item.switch4 === true) && item.text2 !== vorhandene_eintraege.data.gml_id && table1.selectedRow.name_projekt !== vorhandene_eintraege.data.name_projekt ))
    .map(item => ({
    id_vertrag: table1.selectedRow.id_vertrag, // Wert duplizieren
    gml_id: item.text2, // Aus List View
    name_kurz: table1.selectedRow.name_kurz,
    name_projekt: table1.selectedRow.name_projekt,// Wert duplizieren
    fkey_ee_proj: table1.selectedRow.fkey_ee_proj, // Wert duplizieren
    nur_teilflaeche_gesichert: item.switch4
    }))
    }}

The switch filter works perfectly. As you can see in the screenshot on or both of the switches has to be enabled to be saved into the postgresql db. Some of the columns are arrays which may be the root of the problem but im not sure

I hope this covers all necessary information without also being too confusing.
Thank you so much

Is there any part of the data that is unique like a UUID? If so, you could probably add a check for that in a function before running the bulk. update....

1 Like

Hey Scott,
unfortunatly that isnt possible since its an insert and the data that gets inserted cant have a unique id since there are multiple combinations that have to work.

e.g. parcel 1 from person x is in project y but parcel 1 from person x can also be in project z. and project y can also have parcel 2 from person x or parcel 1 from person a.

Hey Scott,
I actually found a workaround with a unique string column.
The problem with the filter still stands. I even tried diffrent "only run when" codes for the event handler which didnt work as well.

e.g.
table1.data.includes(entry => entry.id_vertrag !==
String(vorhandene_eintraege.data.id_vertrag)

{{ table1.data.every( row => vorhandene_eintraege.data.some(entry => entry.id_vertrag === String(row.id_vertrag))) }}

Do you know what the problem with the code could be? The data from vorhandene_eintraege.data is in form of an array since its a select query of the insert table. The table1.selectedRow.id_vertrag data is a string. Could this be the problem?

Greets
Marie

I found a solution.

I did put this code into the only run portion of the event handler:

{{!vorhandene_eintraege.data.id_vertrag.includes(table1.selectedRow.id_vertrag)}}

1 Like