Antonio Kibbutz
Posts: 0
Joined: Fri Feb 20, 2015 7:29 pm

Where condition iwith local storage variable in JS Query

Hi! I've got two buttons on UI layer and if clicked they set two different local storage variables eg: a and b.
Now I'm trying to refine the Rest Service in "Before Send" and I have to put them together in the where condition of my Service.
Something like select * from table where a.table ='value1' and b.table='value2' but in the little JS function I can write in where condition it recognizes a local storage value so I'm not able to use them together, how can I write an and relation?
In my mind I want to set all the filter of the query by clicking the selection and in the end finding all the records in the DB that have those conditions

PS Sorry for my Englih :D

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Where condition iwith local storage variable in JS Query

Perhaps - if I understand your situation correctly - you would be doing this in the blue JS button to the left of of where clause that you are passing to your service would be like this:

var swhereclause = '' ;

swherclause = '{ "field_a_nameinyourcollection": "' + localStorage.getItem('field_a_valuethatgetssetinyourbuttonfor_a') + '","field_b_nameinyourcollection": "' + localStorage.getItem('field_b_valuethatgetssetinyourbuttonfor_b') +'" }' ;

return swhereclause;

That might not be it exactly - but you get the idea... and be sure to distinguish between the double and single quotes in the syntax. Here I've used the string identifiers to form the string that gets sent to your whereclause as the single ' - and the quotes that will actually be passed to the rest service as part of your where clause as the double " quote.

Not sure if that helps- but - i thought I'd jump in until someone from Appery does.

Bruce

Antonio Kibbutz
Posts: 0
Joined: Fri Feb 20, 2015 7:29 pm

Where condition iwith local storage variable in JS Query

Well done! You give me the idea and in the end the solution was
var a =localStorage.getItem('ButtonA');

var b =localStorage.getItem('ButtonB');

return '{ "FieldA":"'+a+'" , "Fieldb":"'+B+'" }';

You help me a lot!! :D

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Where condition iwith local storage variable in JS Query

Glad to help ... Happy coding !

Return to “Issues”