How run one script first then run a query, not in parallel

I got this use case

image

when i finish running query 1 i need to set a temp state, then run a query#2, i tried putting both in the same sucess but they run wrong, sometimes it works, sometimes not. How i can force to run first the setValue for the temp state, then just after, run the query#2 ?

thank you

Use Run script option and put them both in there one after the other...
Screenshot 2022-12-13 at 1.57.40 PM

1 Like

yes i tried that, but the query trigger runs like first

insert into purchase_lines (created_at, product_id, quantity, transaction_id, updated_at, variation_id) values ('2022-12-13T13:23:06-05:00', 41, 10, NULL, '2022-12-13T13:23:06-05:00', '42'), ('2022-12-13T13:23:11-05:00', 40, 2, NULL, '2022-12-13T13:23:11-05:00', '41') - Cannot add or update a child row: a foreign key constraint fails (dbs_sistemainventario.purchase_lines, CONSTRAINT purchase_lines_transaction_id_foreign FOREIGN KEY (transaction_id) REFERENCES transactions (id) ON DELETE CASCADE)

if you see transaction_id is NULL in the INSERT

i got a transformer like this

and use it in the insert

when i run manually the query2 it works good

hmmm...
ok so maybe you can set it as in your screenshot but only allow the crearOC2 query to run when saveTransactionID_OC state is not "" or null or undefined. And you can set the saveTransactionID_OC to run when input values are changed and it will only run once the saveTransactionID_OC actually contains a value

1 Like

woh, can you give me some example? its kinda confusing

i tried this

and this

saveTransactionID_OC is a temp state

I mistyped - sorry about that - try again with some screenshots...

In your first screenshot remove the Event handler saveTransactionID_OC but leave the saveTransactionID_OC.setValue()

ok so maybe you can set it as in your screenshot but only allow the crearOC2 query to run when saveTransactionID_OC state is not "" or null or undefined.

And you can set the crearOC2 to run when input values are changed and it will only run once the saveTransactionID_OC actually contains a value

then when your crearOC2 query succeeds then clear the saveTransactionID_OC state by running the Event handler like the following:
Screenshot 2022-12-13 at 2.25.11 PM

1 Like


i got this, but then query 2 is not running at all

Remove crearOC2.trigger() from Success handler in crearOC1 query
When crearOC1 Succeeds, you set saveTransactionID_OC value
When crear0C2 sees the saveTransactionID_OC value change it will fire...

1 Like

did that, but is not firing

OK two things:
What is the value being set for saveTransactionID_OC is it the value of crearOC1.data?
And save the app and then reload the page - sometimes Retool gets stuck... :slight_smile:

1 Like

image

OK and what is the result when you hover over it when the query has completed?

1 Like

85 its a number that i include in my query2 in the transformer

image

all that works but manually

I made a very big mistake so sorry
When disabling the crearOC2 query use the following:

{{saveTransactionID_OC.value === '' || saveTransactionID_OC.value == undefined || saveTransactionID_OC.value === null}}

Screenshot 2022-12-13 at 3.18.43 PM

2 Likes

works good, thank you very much