Page 1 of 1

Query response empty or not?

Posted: Sun Feb 23, 2014 2:22 am
by Homan Mohammadi

Hi,

I am trying to write an if statement in JS to check whether the response of a query service is empty or not (i.e. query responds something or nothing at all). How would I go about doing this? I cannot seem to find instructions on getsatisfacion or the appery.io documentations.

Thanks for your help in advance!


Query response empty or not?

Posted: Sun Feb 23, 2014 3:23 am
by Illya Stepanov

Hi Homan,

You can take a look here, if it helps: https://getsatisfaction.com/apperyio/...


Query response empty or not?

Posted: Mon Feb 24, 2014 7:54 pm
by Homan Mohammadi

Hi Illya,

Thanks for the response. I still can't seem to get it to work. In the link that you provided, the query response looks like:
{

"html_attributions" : [

],

"results" : [

],

"status" : "ZERO_RESULTS"

}

However, this is what I get when I test the response with a value that isn't in the database:
a Image

For your reference, if the value is in the database, I get the following instead:
Image

Just so you see the full picture, I am triggering the following JS when the page loads:
Image

and then running the following JS once the query is done:
Image

I'm hoping to see "not in database!" when the queried number is not in the database.

Thanks in advance for your help!


Query response empty or not?

Posted: Mon Feb 24, 2014 9:11 pm
by Kateryna Grynko

Hi Homan,

On Success event check the length of array 'data':
preif (data.length === 0){
//---- do something
} else {
//--- do something
}/pre


Query response empty or not?

Posted: Mon Feb 24, 2014 9:29 pm
by Homan Mohammadi

Hi Katya,

Thanks for your response. The code still doesn't seem to work. I tried checking the value of data.length right before the if statement using alert, and the value is 3. Not sure why this might be ...

thanks,
Homan


Query response empty or not?

Posted: Mon Feb 24, 2014 9:33 pm
by Homan Mohammadi

This is the total number of rows in my database. Am I not executing the query correctly? The query is (image included above):

// turn input into integer and insert into userinfo collection
var v = parseInt(Appery("mobilelabel_21").text());
console.log(v);
userinfo_query_test.execute({"data": {"mobilenum": v }});

For your information, mobilenum is a "number" column in my collection.


Query response empty or not?

Posted: Mon Feb 24, 2014 10:10 pm
by Homan Mohammadi

Hi Katya,

I was actually able to get it to work! Thanks for your help!