Anvil Transactions add a transaction ID

Hi

When you set up a transaction on a form for multiple table postings, does Anvil have specific code to add a transaction reference, or what is the recommended way to add this?

When we coded the program on our local python console we used rand int, but I dont really want it to be random, I want it to be a sequence, starting from a certain number.

Would welcome suggestions on what others have done. Thanks in advance.

This is possibly a relevant discussion from a couple of years back:

You’ve also prompted me to to get around to making a feature request that’s been at the back of my mind for some while:

1 Like

Thanks I will create a counters table and add the code suggested on your AI Field Thread. Its a detailed transaction with several tables to update, so fingers crossed it works :slight_smile:

I would say that setting up a transaction on a form for multiple table posting is not a recommended way in itself.

During the time between the start and the end of the transaction, the rows / tables / database (I don’t know the granularity) involved in the transaction are blocked and can’t be written to. Setting up the transaction on a form means you will have a bunch of roundtrips between the beginning and the end of the transaction, which means the duration of the transaction will be hundreds of times longer than it needs to be.

It can be OK if you can swear that your site is very low traffic, but “setting up a transaction on a form” it is not “the recommended way”.

The recommended way is to have the form collect all the data required for the transaction, pack it in a dict, pass that dict to a server function, then execute the transaction on the server.

This way the time required for the transaction will be much shorter.

3 Likes