Page 1 of 1

Query Products Database Dropdown Based On LocalStorage Variable

Posted: Sun Apr 13, 2014 11:37 pm
by Jon Fusco

Hello,

I know very little about Javascript I have only done only HTML/CSS so forgive this question but I am completely lost here and have been for almost 2 days so I am pleading for some help here from anyone who would be so kind.

We have referred to this previous post and I believe I am very close all the services work but not with a local storage variable, and I'm stuck on the javascript part:
https://getsatisfaction.com/apperyio/...

We have a DB of products that have 4 basic columns SKU, Product Name & Image & LoadID.

Example:
SKU Name Image URL LoadID
BBB1 Garden Hose [url=http://....image1.jpg]http://....image1.jpg[/url] BGSN
BBB2 Clamp [url=http://....image2.jpg]http://....image2.jpg[/url] GAWK
BBB3 Salt Shaker [url=http://....image3.jpg]http://....image3.jpg[/url] ETEN
BBB4 Salt Shaker [url=http://....image4.jpg]http://....image4.jpg[/url] ETEN
BBB5 Salt Shaker [url=http://....image5.jpg]http://....image5.jpg[/url] ETEN

These items are displayed in a listbox "On Load" when the page loads. There are like 10000 items and it takes a while to load, so I'd like to separate them by "LoadID" using a dropdown on the same page. We add new LoadIDs daily, so the LoadID needs to be dynamic and change within a local variable.

I have the service working with the "where" parameter and everything works when I simply put {"LoadID":"ETEN"} in the query. No problems there.

On the page we have a dropdown box that contains all of the LoadID values once. The idea being that we could select the LoadID from the dropdown (It populates onLoad using a List Service) and it would invoke the inventory query service and display only the items where the LoadID=The selected value. When the value changes we have been setting a localstoragevariable(LoadID) within the browser.

So an example would be On ValueChange - Invoke Service "Query Inventory" when the value of our localstorage variable in the dropdown (LoadID=ETEN)

It would display this:
BBB3 Salt Shaker [url=http://....image3.jpg]http://....image3.jpg[/url] ETEN
BBB4 Salt Shaker [url=http://....image4.jpg]http://....image4.jpg[/url] ETEN
BBB5 Salt Shaker [url=http://....image5.jpg]http://....image5.jpg[/url] ETEN

This seems like it should be easy but I have tried most everything. Any help is appreciated, the docs don't have and example of this that I could find.


Query Products Database Dropdown Based On LocalStorage Variable

Posted: Mon Apr 14, 2014 12:29 am
by Jon Fusco

To add to this what I would like to do is very similar to the warehouse app tutorial except instead of scanning a barcode we would like to select from a dropdown and display multiple results, not just a single result like in this tutorial.

http://docs.appery.io/tutorials/wareh...


Query Products Database Dropdown Based On LocalStorage Variable

Posted: Mon Apr 14, 2014 1:04 am
by Rick O'Connor

Not sure if I can help you Jon but I'll give it a shot.

In my (amateur) opinion:

Join the where parameter of your query to the local variable you set from the list.
Add JS. Something like:

var jsLoadID = localStorage.getItem('LoadID');
return '{"LoadID":"'+ jsLoadID+'"}';

Hope this helps.


Query Products Database Dropdown Based On LocalStorage Variable

Posted: Mon Apr 14, 2014 2:15 am
by Jon Fusco

Rick, you are the M-A-N. I was able to do it using that last line of code exactly as you said.

return '{"LoadID":"'+ jsLoadID+'"}';

Maybe you are not an amateur? Thank you that made my night! It worked with a list REST too after I added the "where" parameter.


Query Products Database Dropdown Based On LocalStorage Variable

Posted: Fri Oct 02, 2015 10:50 pm
by james7651922

Jon (or anyone else that may know), where do you add the "where" parameter to the list REST service? I tried just adding it in the Request, but maybe I need some additional syntax.

Thanks,
James


Query Products Database Dropdown Based On LocalStorage Variable

Posted: Sat Oct 03, 2015 12:46 am
by james7651922

Please disregard the last question. The query worked fine with the parameter mapping. My mistake was in the API URL. I left in the where={}, but after removing that it all worked fine.


Query Products Database Dropdown Based On LocalStorage Variable

Posted: Sat Oct 03, 2015 2:53 am
by Evgene Karachevtsev

Hello James,

Thank you for the update.