Hey all!
I use this JS code to create a new entry in my database.
It worked very well until it started creating multiple entries when I trigger this code which should not be the case.
This is my JS code:
const insertTicketQuery = `
INSERT INTO tickets (
"status", "open_date", "description", "label", "contact_id", "location_ids"
) VALUES (
'Eingang', '${dateCreateTicketDate.value}','${txtCreateTicketDescription.value}', '${txtCreateTicketName.value}', '${multiSelectCreateTicketContacts.value}', '${multiSelectCreateTicketLocation.value}'
);
`;
setViewTickets.trigger();
getTicketsListView.trigger();
getTicketsBoardView_realization.trigger();
getTicketsBoardView_preparation.trigger();
getTicketsBoardView_approval.trigger();
getTicketsBoardView_Review.trigger();
getTicketsBoardView_output.trigger();
return insertTicketQuery;
This is my SQL query that returns the data of my JS code:
{{createTicketQuery.data}}
and when I click a button on the UI, the JS code and the query are triggered.
I am triggering the JS code because the query returns an error that disappears if I only run the JS code. So I trigger the JS code to avoid this error.
Does anybody know why multiple entries are created at once?
Thanks in advance.
I'm a little confused what you're trying to achieve here and why you're using this approach to achieve it.
Using inline SQL statements in this way is something I'd advise against
Equally, running 7 triggers from one query might be something that will be a performance problem or could cause a race condition, especially as all these will fire at the same time and could resolve or fail in any order.
Perhaps you can elaborate on what your goal is and what this statement refers to:
I am triggering the JS code because the query returns an error that disappears if I only run the JS code.
1 Like
How about using await, generally it's a good idea to use await when triggering multiple queries at once?
const insertTicketQuery = INSERT INTO tickets ( "status", "open_date", "description", "label", "contact_id", "location_ids" ) VALUES ( 'Eingang', '${dateCreateTicketDate.value}','${txtCreateTicketDescription.value}', '${txtCreateTicketName.value}', '${multiSelectCreateTicketContacts.value}', '${multiSelectCreateTicketLocation.value}' );
;
await setViewTickets.trigger();
await getTicketsListView.trigger();
await getTicketsBoardView_realization.trigger();
await getTicketsBoardView_preparation.trigger();
await getTicketsBoardView_approval.trigger();
await getTicketsBoardView_Review.trigger();
await getTicketsBoardView_output.trigger();
return insertTicketQuery;
1 Like