Different query results

Posted by matman on 19-Sep-2014 10:31

I just wrote a little object script:

var x = "";

x += rbv_api.selectQuery("SELECT id FROM website3", 10);

rbv_api.log("debug", x);

When I put this in the trigger script field and press Debug formula it returns me NULL. When I paste SELECT id FROM website3 in the Test Query section, it returns me all the records IDs. Why is that? It should return the same, right?

Posted by pvorobie on 19-Sep-2014 11:08

The script above returns NULL because there is nothing to return. rbv_api.log() writes output to debug.log file which is available to you through "Log" button. rbv_api.printArr() will print results in Debug window.

All Replies

Posted by pvorobie on 19-Sep-2014 11:08

The script above returns NULL because there is nothing to return. rbv_api.log() writes output to debug.log file which is available to you through "Log" button. rbv_api.printArr() will print results in Debug window.

Posted by Gian Torralba on 19-Sep-2014 11:18
Hello,

Can you try to restructure your code? rbv_api.selectQuery() returns an array of the records specified in the query. Please try this instead:

var websiteArr = rbv_api.selectQuery("SELECT id FROM website3", 10);

for(var i=0; i
var id = websiteArr[i][0]; /*gets the id column value*/
}

Thank you,
Gian
Posted by matman on 22-Sep-2014 05:00

Fridays seem to make me fuzzy, should drink more coffee. And then to think that I had already posted a topic about treating return values.. Anyway, I managed to get it to work using your suggestions. I pasted my script below for future generations. Thanks a lot guys!

	var websiteArr;
	var toString = "";
	
	websiteArr = rbv_api.selectQuery("SELECT id FROM website3", 10);
	
	for(var i = 0; i < websiteArr.length; i += 1) {
		toString += websiteArr[i][0];
	}
	
	rbv_api.log("debug", toString);
This thread is closed