This topic is locked

How to record calculated fields results

6/27/2014 4:00:31 PM
PHPRunner General questions
R
ringlis1 author

On page 478 of the manual, I used the tutorial on "How to calculate values on the fly".
I have 3 fields to calculate

Quantity

Hours

CostEach (cost each hour)
I have the results store in a 4th field [SubTotal]
The results are show on the list page and view page, however, nothing is stored in the SubTotal field. Here is the code that I have so far. It currently is only set to calculate 2 of the fields. I also need to set up the calculation to work if [Hours] is not used for a specific record.

var ctrlCostEach = Runner.getControl(pageid, 'CostEach');

var ctrlQty = Runner.getControl(pageid, 'Qty');

var ctrlHours = Runner.getControl(pageid, 'Hours');

var ctrlSubTotal = Runner.getControl(pageid, 'SubTotal');

function func() {

ctrlSubTotal.setValue(Number(ctrlCostEach.getValue()) * Number(ctrlQty.

getValue()));

};

ctrlCostEach.on('keyup', func);

ctrlQty.on('keyup', func);

ctrlHours.on('keyup', func);


Thank you in advance.

Sergey Kornilov admin 6/30/2014

I'm not quite sure I understand. You are saying that calculated value appears fine on List/View pages while this code is only supposed to work on Add/Edit pages. You can probably elaborate it a little bit more.

emendoza 6/30/2014

Hi JetSkiBum

I used a code like the following, which worked for me:
----------------

var ctrlPrecio = Runner.getControl(pageid, 'Precio_de_compra');

var ctrlCantidad = Runner.getControl(pageid, 'cantidad');

var ctrlTotal = Runner.getControl(pageid, 'totalc');

function func() {

ctrlTotal.setValue((+ctrlPrecio.getValue()) (+ctrlCantidad.getValue()));

};

ctrlPrecio.on('keyup', func);

ctrlCantidad.on('keyup', func);

----------------
I believe that the error is in the following line:
----------------

ctrlSubTotal.setValue(Number(ctrlCostEach.getValue())
Number(ctrlQty.

getValue()));

----------------
try replacing these lines by these
----------------

ctrlSubTotal.setValue(Number(+ctrlCostEach.getValue()) * Number(+ctrlQty.

getValue()));

----------------
Regards, I am to order

R
ringlis1 author 7/2/2014



I'm not quite sure I understand. You are saying that calculated value appears fine on List/View pages while this code is only supposed to work on Add/Edit pages. You can probably elaborate it a little bit more.


I want the code to store the results. However, it is only showing the results on the view page. When I go to the edit page or view the actual database fields the results amount does not update the database

R
ringlis1 author 7/2/2014

emendoza - I tried adding the +, but that seems to give me the same results.
I have the subtotal set to add a total, but, since the results are not being stored, the total is 0

emendoza 7/2/2014

friend,
the following link will give you a taste of what I've done,

I've only used the following code should be placed in the javascript onload event in the edit page and add page

----------------

var ctrlPrecio = Runner.getControl(pageid, 'Precio_de_compra');

var ctrlCantidad = Runner.getControl(pageid, 'cantidad');

var ctrlTotal = Runner.getControl(pageid, 'totalc');

function func() {

ctrlTotal.setValue((+ctrlPrecio.getValue()) *

(+ctrlCantidad.getValue()));

};

ctrlPrecio.on('keyup', func);

ctrlCantidad.on('keyup', func);

-------------------
here I send sql table file 'compras' with which the code runs.

In the visual editor must check the box "apply on the edit page as well" so you can change the value of "precio" to change the value of "Producto".


greetings friends

Sergey Kornilov admin 7/3/2014

I'm sorry, just completely lost. How can something be displayed on the View page (where data is coming from the database) and at the same time results are not stored in the database.
How can you display something that is not stored in the database?
If you need more help publish your project to Demo Account and contact support directly. This doesn't make much sense to me.

N
nti 7/3/2014

I think he is trying to store/save a custom calc field into a database field/col, so, JetSkiBum... is this what you are trying to do?