Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

"or" condition in Javascript query using LS variable

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

obullei
Posts: 0
Joined: Thu Jun 05, 2014 12:17 am

"or" condition in Javascript query using LS variable

Hello!

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

"or" condition in Javascript query using LS variable

Helle Peter,

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

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

"or" condition in Javascript query using LS variable

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

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

"or" condition in Javascript query using LS variable

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?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

"or" condition in Javascript query using LS variable

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.

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

"or" condition in Javascript query using LS variable

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);

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

"or" condition in Javascript query using LS variable

Hi Peter,

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

Return to “Issues”