Hi,
I have no experience with javascript, and I need to sum the total value in a quantity field in the database. What is the best way to sum the total quantity across several lines and display it in a text field?
Thanks
Preben
Hi,
I have no experience with javascript, and I need to sum the total value in a quantity field in the database. What is the best way to sum the total quantity across several lines and display it in a text field?
Thanks
Preben
Hi!
Assuming that you want to sum over some float property of an object class:
In the function editor, add a data source containing the objects you want to sum over as a function parameter. If the data source we want to use is called salesLines
and the property we want to sum over is called amount
, the code would look like this:
return salesLines.reduce((agg,obj) => (agg + obj.amount), 0)
Read more about functions and see some examples, including the one I just provided, in our Documentation.
Hope that helps!