Page 1 of 1

Make query use a local variable

Posted: Sun Jun 01, 2014 3:33 pm
by Jamie Steiner6905824

How do I access local variables as a parameter in a query? for example, for a ToDo app where users can assign task to each other, i'd like to make a list service access all records where: {"Assignee": {"$inQuery": {"_id": UserID}}} Where UserID is a local storage variable that was returned upon the users login, via a login service. I linked them using the request mapping tab, and tried a few ways (obvious to me) of adding javascript, but no joy. I assume this is possible, but I am struggling with the syntax. I also didn't see anything useful in the docs, maybe I missed it, but I'm a RTFM kind of guy...


Make query use a local variable

Posted: Sun Jun 01, 2014 6:10 pm
by Igor

Hello,

You can invoke JavaScript in your service before and after mapping.
Put below code in your service-request tab-where clause-add JS
pre
var UserID = localStorage.getItem('UserID');
return '{"Assignee": {"$inQuery": {"_id": "' + UserID + '"}}}';
/pre

or you can map local storage variable to the where clause and use next code:

pre
return '{"Assignee": {"$inQuery": {"_id": "' + value + '"}}}';
/pre

This doc should be helpful:
http://devcenter.appery.io/documentat...