Field calcation failes

Hi all,

I have strange issue with a field who calculates a total price based on function.
I have 2 windows above window which displays total prices. The window below has the specs.
When I duplicate a spec and change the price of the spec the total price in the above window is not calculated or does a strange calculation.
After editing/changing the price in the spec the total price is calculated normally.

The total price field has the dataProvider set to the function below

function:

function calc_inkoopprijs()
{
if(databaseManager.hasRecords(bcom_full_verkorderregels_to_inkorderspecregels))
{
var Aantal = databaseManager.getFoundSetCount(bcom_full_verkorderregels_to_inkorderspecregels.foundset) //(getfoundsetcount ivm >200)
var _tot1 = 0.00
for(var i = 1; i <= Aantal; i++)
{
var vRecord = bcom_full_verkorderregels_to_inkorderspecregels.getRecord(i);
_tot1 = _tot1 +(vRecord.inkorsrgl_ik_prijs * vRecord.calc_aantal_totaal)
}
return _tot1;
}
else
{
return 0;
}
}

Has this something to do with the loaded foundset? Or can someone explain this issue to me?

Servoy 7.3.1
Postgresql 9.3

Tnx in advance
Derk

Hi Derk,

why don’t you use a standard Servoy aggregate to achieve this?
I think that will be much faster.

Hi Marc,

The function is a calculation not a aggregation
But I think the calculation is used because is calculates values from a different foundset then the loaded foundset.
Correct me if I am wrong :)

Traversing foundsets in calculations is generally considered to be a bad thing. Much better to assign potentially long(-ish) running code to events that you have 100% control over.