rbf_SelectNumber: variable = still undefined

Posted by Rollbase User on 05-Oct-2010 04:05

Hi. There are 12 records in the Object: object. 'que2' must equate to the variable 'querycount' so that I can use it to my condition. The problem is it won't equate.. why is that? Here's my code (javascript): var querycount; rbf_selectNumber("SELECT COUNT(1) FROM object", function(que2) { alert(que2); querycount = que2; } ); alert(querycount); the OUTPUT: que2 = 12 querycount = still undefined Is there a problem in my code? Same goes to SelectQuery & SelectValue, the result is undefined.. Thank You.

All Replies

Posted by Admin on 05-Oct-2010 11:48

The result is 12 - please check your output.

Posted by Admin on 05-Oct-2010 20:43

the result is still undefined. By the way I'm using Rollbase.ph . Thanks for the reply

Posted by Admin on 25-Feb-2011 23:50

I got a similar problem because of a race condition.
Here is the solution:

var querycount;
rbf_selectNumber("SELECT COUNT(1) FROM object", function(que2)
{ querycount = que2; after(); } );

// depending on the timing at runtime, querycount may not be defined yet
// you have to wait for the callback function to return

after() {
// now querycount is defined
alert(querycount);
}

Posted by Admin on 26-Feb-2011 11:25

rbf_selectNumber API, like other AJAX-based APIs operates asynchronously. So the best approach would be to process result inside callback function rather than use global variable.

I will add this info to documentation.

Posted by Admin on 26-Feb-2011 14:28

You are right. The correct way should be:

rbf_selectNumber("SELECT COUNT(1) FROM object", callback_count);
function callback_count(querycount) {
alert(querycount);
}

This thread is closed