I have the following script in a Rollbase page. It selects a VAT rate based on a VAT code in the page and calculates the VAT Amount. However we get a message about exceeding API calls (limit being 1000) after just a dozen or so calculations.
In order to get round this for now I want to just hard-code the VAT Rate (20%) in the script and not perform any API calls - which I am assuming is the "Select vat_rate etc..."
So I think I want vatDec to be assigned a value of 20.
However whatever modifications I try I cannot get it to work.
I would be grateful for pointers as to what modification would work. Thanks. Richard.
function computePrice() {
var goods = rbf_getFieldValue("goods");
var taxCode = rbf_getFieldValue("vat_cd");
rbf_selectValue("SELECT vat_rate FROM vat_rate WHERE vat_code='"+taxCode+"'", function(vatDec) {
var vatAmt = parseFloat(goods.substring(1)) * (parseFloat(vatDec) / 100);
var total = parseFloat(goods.substring(1)) + vatAmt;
rbf_setFieldValue("vat", vatAmt);
rbf_setFieldValue("price", total);
$("input#vat, input#price").blur();
});
}
API calls are rbf_selectValue(), rbf_getFieldValue() and rbf_setFieldValue() calls. So it's likely the rbf_setFieldValue() that sink you (you call it twice for each record from the SELECT query).
API calls are rbf_selectValue(), rbf_getFieldValue() and rbf_setFieldValue() calls. So it's likely the rbf_setFieldValue() that sink you (you call it twice for each record from the SELECT query).
Flag this post as spam/abuse.
You might want to add some debugging information to trace how many times the rbf_... functions are called. The computePrice() function may be called more often than you think, or the SELECT statement might return more records than you think.