Page 1 of 1

"or" condition in Javascript query using LS variable

Posted: Sat Jul 12, 2014 7:14 am
by Peter Viglietta

Hello,

I'm building a messaging system in my app. I have a table called MessageThreads that has two columns, SentToID and SentFromID, which are the User IDs that sent or received a message. Also, when the users log into my app, it sets a Local storage variable CurrentUserId.

Can someone give me the Javascript I need to put in the Where request parameter for the query service on the MessageThreads table, so that it returns a list of all MessageThreads where the LS variable "CurrentUserId" is either the SentToId OR the SentFromID?

Any help is much appreciated, thanks


"or" condition in Javascript query using LS variable

Posted: Sat Jul 12, 2014 11:28 am
by obullei

Hello!

Please take a look to this thread: https://getsatisfaction.com/apperyio/...
This may be helpful.
If you will have any questions, please ask.


"or" condition in Javascript query using LS variable

Posted: Sat Jul 12, 2014 2:36 pm
by Alena Prykhodko

Helle Peter,

Just to add, please find more about local storage here http://devcenter.appery.io/documentat...


"or" condition in Javascript query using LS variable

Posted: Sat Jul 12, 2014 6:21 pm
by Peter Viglietta

Please see screenshot below...
The LS variable CurrentUserID is the user ID of whoever is logged in.
I want the MessageThreads screen to display all rows from MessageThreads where the currentUserID is either the SentToId or the SentFromId on the message threads table... is that possible using Javascript? Thanks!
Image


"or" condition in Javascript query using LS variable

Posted: Sun Jul 13, 2014 3:10 am
by Peter Viglietta

I tried this out a few different ways but still can't get it to work... The code below is wrong, because it returns all rows where the local storage variable CurrentUserId is both the SentToId and the SentFromId. How can I write it so that it returns all rows where the CurrentUserId is either the SentToId or the SentFromId?

var CurrentUserId = localStorage.getItem("CurrentUserId");
var whereObject = {"SentToId": CurrentUserId, "SentFromId": CurrentUserId};
return JSON.stringify(whereObject);

Also.. can someone explain to me, is this technically JSON or just Javascript? Where can I read up on how to write this code?


"or" condition in Javascript query using LS variable

Posted: Sun Jul 13, 2014 1:19 pm
by Alena Prykhodko

Hello Peter,

As you can find here http://blog.appery.io/2014/05/what-is... the resulting app is built with jQuery Mobile, HTML5, JavaScript, CSS and PhoneGap (if exporting as hybrid or using native device features). Please also see What is an Appery.io app?

So, all code used to build app is pretty standard stuff and you can use any available custom logic.

You can use queries http://devcenter.appery.io/documentat... or filter data with JavaScript.


"or" condition in Javascript query using LS variable

Posted: Sun Jul 13, 2014 5:56 pm
by Peter Viglietta

I know this is wrong, but would it be something like this? Is what I'm trying to do not possible? Can someone help me out here please?

var CurrentUserId = localStorage.getItem("CurrentUserId");

var whereObject = {"SentToId": CurrentUserId} $or {"SentFromId": CurrentUserId};

return JSON.stringify(whereObject);


"or" condition in Javascript query using LS variable

Posted: Sun Jul 13, 2014 9:40 pm
by Illya Stepanov

Hi Peter,

In our documentation described how to use logical operator $or clause here:
:: http://devcenter.appery.io/documentat...


"or" condition in Javascript query using LS variable

Posted: Sun Jul 13, 2014 10:09 pm
by Peter Viglietta

Thanks Illya!