Inserting calculated value to DB field automatically

Hi!

Just wanted to ask if it is possible to insert the calculated value of two fields to an other field automatically.

For example: Quantity * Price is inserted to an another field (in the same table) called Subtotal when i insert Quantity and Price using a form.

And how?
Any help would be appreciated.
Thanks!

Re: Inserting calculated value to DB field automatically

Hi all!

Found the answer and if anyone is searching for the same kind of solution::

Event: onAfterInsert
Code: sc_exec_sql(“UPDATE Tablename SET Field=’{Quantity}’*’{Price}’ WHERE Quantity = ‘{Quantity}’ AND Price = ‘{Price}’”);

One whole day for this…

Thanks anyways.

Re: Inserting calculated value to DB field automatically

Please, use in events onBeforeInsert and onBeforeUpdate like this:

{subtotal} = {Quantity} * {Price}

Your solution works, but also is a query more …

Re: Inserting calculated value to DB field automatically

Or you can use on the event onValideSuccess … this will prevent you to duplicate the code(for before insert and before update). to beforedelete its insignificant.

Re: Inserting calculated value to DB field automatically

Hi!
Yes, actually I used the same code in onAfterUpdate also, and it’s working fine and does what i want it to do. I will also try to use the solutions proposed and see.

Thanks for your replies.