How to Access Calculations associated with a table

Other than creating a field on a form. How do you programmatically access a calculation associated with a DATABASE TABLE? Are they considered globals?

example:

/**
*

  • @properties={type:6,typeid:36,uuid:“9f1da685-5ef7-44af-b019-29f5cf19b25a”}
    */
    function c_0_30_total_due()
    {
    var vTotal = 0
    var recordCount = advertiser_invoices_self_adv_id.getSize();
    for (var i = 1; i <= recordCount; i++)

{
var vRecord = advertiser_invoices_self_adv_id.getRecord(i)
vTotal = vTotal + vRecord.c_0_30
}
return vTotal

}
Daryl

Hi Daryl,

Calculations can be accessed as normal fields in a foundset or record.
Your example calculation could be accessed as

var _rec = foundset.getSelectedRecord();
var _nTotalDue = _rec.c_0_30_total_due();

Off topic, on the content of your calculation:

  1. Using relations and even looping record as you do, can make your solution slow.
    Maybe you can explain what you are trying to accomplish

  2. When looping a foundset, you should not store advertiser_invoices_self_adv_id.getSize() in a variable.
    Servoy will only get you the size of the first chunk, in case you have more than 200 (foundset) or 60 (related foundset) records, this loop will only handle those 200 or 60 records.
    Use it in a for-loop like below and Servoy will get the next chunk when it reaches the last record of the current chunk:

for (var i = 1; i <= advertiser_invoices_self_adv_id.getSize(); i++)

Hope this helps