How to Access Calculations associated with a table

Questions, tips and tricks and techniques for scripting in Servoy

How to Access Calculations associated with a table

Postby dlclark » Wed Mar 30, 2022 12:05 am

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
dlclark
 
Posts: 35
Joined: Sat Jan 08, 2022 5:39 pm

Re: How to Access Calculations associated with a table

Postby mboegem » Wed Mar 30, 2022 8:51 am

Hi Daryl,

Calculations can be accessed as normal fields in a foundset or record.
Your example calculation could be accessed as
Code: Select all
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:

Code: Select all
for (var i = 1; i <= advertiser_invoices_self_adv_id.getSize(); i++)


Hope this helps
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1594
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Methods

Who is online

Users browsing this forum: No registered users and 3 guests