Homan Mohammadi
Posts: 0
Joined: Mon Feb 17, 2014 10:30 pm

Query response empty or not?

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!

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Query response empty or not?

Hi Homan,

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

Homan Mohammadi
Posts: 0
Joined: Mon Feb 17, 2014 10:30 pm

Query response empty or not?

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!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Query response empty or not?

Hi Homan,

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

Homan Mohammadi
Posts: 0
Joined: Mon Feb 17, 2014 10:30 pm

Query response empty or not?

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

Homan Mohammadi
Posts: 0
Joined: Mon Feb 17, 2014 10:30 pm

Query response empty or not?

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.

Homan Mohammadi
Posts: 0
Joined: Mon Feb 17, 2014 10:30 pm

Query response empty or not?

Hi Katya,

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

Return to “Issues”