Need to modify script to avoid API call

Posted by RichardWalsh on 05-May-2014 08:40

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();
    }); 
}

All Replies

Posted by Laurent on 05-May-2014 09:30

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).

Posted by RichardWalsh on 06-May-2014 07:05

Thanks for the info Laurent.
Even though the rbf_setFieldValue() is called twice I can't understand how it can trip over a 1000 API call limit with just a handful of records input


[collapse]
From: "Laurent" <bounce-lpoulain@community.progress.com>
To: "TU Rollbase" <TU.Rollbase@community.progress.com>
Sent: Monday, 5 May, 2014 3:31:29 PM
Subject: RE: Need to modify script to avoid API call

Reply by Laurent

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).

Stop receiving emails on this subject.

Flag this post as spam/abuse.


[/collapse]

Posted by Laurent on 06-May-2014 08:19

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.

This thread is closed