Janko
Posts: 0
Joined: Tue Mar 12, 2013 11:59 pm

Query with Where condition invoked by Javascript

Hi,

I am struggling to invoke a DB REST service from Javascript with a where condition.
I always get all the records. This is the (last) relevant part of the code I am using:

recordId = 123456 // it's inside a loop, changing each loop
QueryToLaunch='{where={"FieldName": {"collName":"LinkedCollectionName", "_id":"' + recordId + '"}}}'
ServiceDefined.execute(QueryToLaunch)

ServiceDefined is a query service on aTiggzi DB collection. I tried both having and not having the "where" (blank) parameters defined in the service itself (what is the right solution by the way?) with no luck.

I already look at ANY documentation I found, tried several solution, but none worked.
Please provide the right javascript code, don't point me to uncomplete documentation.

Thanks! Marco.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Query with Where condition invoked by Javascript

Please check in Chrome Dev. Tools Network (or Firebug) the request that's being sent, to make sure it has the right syntax. If still not working, please paste the entire request that's being sent.

Janko
Posts: 0
Joined: Tue Mar 12, 2013 11:59 pm

Query with Where condition invoked by Javascript

Thanx .. Uhm.. There must be something definitely not working as expected !!! ....

With this QueryToLaunch var
where={'BikeArea': {'collName':'BikeArea', '_id':'5138db5ee4b0fa3619e9d683'}}

the following request /response is produced.
note that each char in the QueryToLaunch generated a separate URL parameters !!!! (note aso that I deleted for security reasons both project ID from URL and DB ID):

Request URL:https://api.tiggzi.com/rest/1/db/coll...
Request Method:GET
Status Code:200 OK

Request Headersview source
Accept:application/json, text/javascript, /; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,en-GB;q=0.2,fr;q=0.2
Connection:keep-alive
Host:api.tiggzi.com
Origin:http://project.tiggzi.com
Referer:http://project.tiggzi.com/view/xxxxxx...
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
X-Tiggzi-Database-Id:xxxxxxxxxxxxxxxxxxxxx

Query String Parametersview parsed
0=w&1=h&2=e&3=r&4=e&5=%3D&6=%25&7=7&8=B&9='&10=B&11=i&12=k&13=e&14=A&15=r&16=e&17=a&18='&19=%3A&20=%25&21=2&22=0&23=%25&24=7&25=B&26='&27=c&28=o&29=l&30=l&31=N&32=a&33=m&34=e&35='&36=%3A&37='&38=B&39=i&40=k&41=e&42=A&43=r&44=e&45=a&46='&47=%2C&48=%25&49=2&50=0&51='&52=_&53=i&54=d&55='&56=%3A&57='&58=5&59=1&60=3&61=8&62=d&63=b&64=5&65=e&66=e&67=4&68=b&69=0&70=f&71=a&72=3&73=6&74=1&75=9&76=e&77=9&78=d&79=6&80=8&81=3&82='&83=%25&84=7&85=D&86=%25&87=7&88=D

Response Headersview source
Access-Control-Allow-Origin:http://project.tiggzi.com
Connection:keep-alive
Content-Type:application/json
Date:Thu, 21 Mar 2013 00:14:37 GMT
Server:nginx
Set-Cookie:JSESSIONID=SFqM1zfjzgkgjkjgbkj.undefined; Path=/; Secure
Transfer-Encoding:chunked

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Query with Where condition invoked by Javascript

As you are sending a request from custom JavaScript (not from an app built in Tiggzi), I don't really know why this happens. The "where" parameter should be urlencoded.

Janko
Posts: 0
Joined: Tue Mar 12, 2013 11:59 pm

Query with Where condition invoked by Javascript

Ok.

Isn't this
ServiceDefined.execute(QueryToLaunch)

native Tiggzi code?
(I got it from http://help.gotiggr.com/documentation...)

If not, how can i invoke a service via Javascript passing to it the query condition ?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Query with Where condition invoked by Javascript

Are you invoking the service from a Tiggzi-built app or an app built completely outside of Tiggzi?

Janko
Posts: 0
Joined: Tue Mar 12, 2013 11:59 pm

Query with Where condition invoked by Javascript

Hi,
Tiggzi completely built-in app.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Query with Where condition invoked by Javascript

To pass data to the service this way would look like this:

code
service_instance.execute({'data': {'where': '....'}});
/code

Janko
Posts: 0
Joined: Tue Mar 12, 2013 11:59 pm

Query with Where condition invoked by Javascript

Thanks Max.. we are on the right way but not still there I believe.

it seems like any string included in {} is slit in char and each char treated as a parameters in the querystring.

this Instancename.execute({ "data" : "'where': '{'_id':'5140eb66e4b0fa3619eaade8'}' " })
causes this:

Query String Parametersview sourceview URL encoded
0:'
1:w
2:h
3:e
4:r
5:e
6:'
7::
8:
9:'
10:{
11:'
12:_
13:i
14:d
15:'
16::
17:'
18:5
19:1
20:4
21:0
22:e
23:b
24:6
25:6
26:e
27:4
28:b
29:0
30:f
31:a
32:3
33:6
34:1
35:9
36:e
37:a
38:a
39:d
40:e
41:8
42:'
43:}
44:'
45:

If i try as you suggested, like:
.execute({'data' : {'where':{'_id': '5140eb66e4b0fa3619eaade8'}} })
this is how the URl is encoded:
https://api.tiggzi.com/rest/1/db/coll...

How should I correct this?
thx

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Query with Where condition invoked by Javascript

Hello! Try this
codeInstancename.execute({ "data" : {"where": '{"_id":"5140eb66e4b0fa3619eaade8"}'}});/code

Single and double quotes are important

Return to “Issues”