Page 1 of 1

How to pass along database and input values?

Posted: Wed Jul 09, 2014 11:26 pm
by Ed Chmiel

Hi, I have a collection (Call it "C"), and the standard user collection. So on the login page (using the register/login sample tutorial), I would like to be able to save the username for use on another page's query. For example, log in Joe, and then on the next page, display all records in C where UserID==Joe.

I have tried to map the username to a local storage variable ("Userid") on the login start page. It maps (arrow goes to the local var), but I don't ever get a value. I have an event on the next page for Load event:

var str = localStorage.getItem('Userid');
alert(str);

and it shows null.

If you are kind enough to show me how to get the value, then would I be able to use the same idea for my query? I'd like the query to be where UserID: . (UserID is a column in the collection).

thanks, and please answer in newbie terms, this is all new to me as an old fashioned C++ guy :-)


How to pass along database and input values?

Posted: Thu Jul 10, 2014 4:15 am
by Yurii Orishchuk

Hi Ed,

Your code to get LSV value looks ok.

So i guess the problem is in the set LSV processing.

Thus please specify how do you do it. Screen shots will help.

Also try to invoke following code to store LSV on success event for login service.

pre

//Note: you should replace "yourLoginInputName" with your login input name value.
var login = Apperyio("yourLoginInputName");

//Store recieved value in the LSV.
localStorage.setItem("Userid", login);

/pre

Regards.


How to pass along database and input values?

Posted: Thu Jul 10, 2014 11:04 pm
by Ed Chmiel

Thanks, that's better, but not quite what I want - now the alert shows [object Object]. I want to get the text string that is the username that was entered on the login screen.

I plan to use that in database queries like where UserID: localStorage.GetItem("UserID"). Obviously I need some other function to extract the string. I am pretty familiar with sql queries and plan to use query services.

So I would like to enter JavaScript into the request where field:

return '{"UserID":"'+value+'"}';

(from your build a search app tutorial)
but not sure what +value+ should be to get the user id string from the local storage.

Unless you have a better way? I am all ears :-)


How to pass along database and input values?

Posted: Thu Jul 10, 2014 11:45 pm
by Ed Chmiel

OK, further, I did this (for other's reference)
login page on success:

var login = Appery('existinguser');
//Store recieved value in the LSV.
localStorage.setItem("Userid", login.val());
var str = localStorage.getItem("Userid"); //use this anywhere in app to get username

Ok, but now to the database query: I dont know what to map to where field? Localstorage variable Userid or ? ANd then what for the java script so I can do like I asked above?
thx


How to pass along database and input values?

Posted: Fri Jul 11, 2014 1:48 am
by Yurii Orishchuk

Hi Ed,

Please follow these steps:

1 Open your service mapping.

2 Add "Userid" LSV to your mapping with following way: http://prntscr.com/41gpkp/direct

3 You will get this "Userid" LSV in the bottom of right side panel. http://prntscr.com/41gq1a/direct

4 Make link from just created "Userid" LSV to request field you need. http://prntscr.com/41gqby/direct

That's all.

Regards.