Page 1 of 1

Loop a REST weather service through list

Posted: Wed Apr 20, 2016 12:02 am
by Anthony Berko

Hi guys

I have read through some similar posts but cannot find an answer that works. Im hoping its an easy fix this one but here goes.

I have a weather service using Wunderground weather API. Unfortunately they can only return a single weather location per query. What I have is a list that I will be changing every week and I would like the service to loop through that list of locations and return the weather at a glance in the list.

I can get it to work for a single list item perfectly. But if I populate a list of locations the service does not return any weather not even for the first item in the list.

Here is what is looks like with 1 item

Image

If i then map the list to load all locations..

Image

It will list all locations from my database..

Image

Now that the mobilelistitem_9 is successfully loaded I need something to run the REST service for the first item in list "Australia/Sydney" and return the weather in a grid for that item and do this for each location.

Could you please provide me with any help as to what code I could use for this loop.

Thanks Anthony


Loop a REST weather service through list

Posted: Wed Apr 20, 2016 2:37 pm
by Serhii Kulibaba

Hello Anthony,

Please clarify the question. What is the difference between mapping of the only one item and list items?


Loop a REST weather service through list

Posted: Wed Apr 20, 2016 11:09 pm
by Anthony Berko

Hi Sergiy

If I map only one list item a weather REST service successfully takes the value of a label box in the list item and queries a weather API and returns the weather results to the same list item. If you see the first image I posted it shows this.

However if I map all list items, the REST service appears to do nothing on completion of the list being populated. If you look at the 3rd image I posted you can see the complete list but no weather information is returned (not even the first list item).

It appears that there is no way I can have the weather REST service run for each list item as the list is being populated.. So Im hoping there is a way I can run a loop after the list is displayed that will iterate through each list item and get the value of the label box in the list item and pass it to the query in the weather REST service and then the service will return weather for that location in the list item to a grid in the same list item. The loop will have to so this for each item in the list.

I realise this loop will be slow on the app but thats ok.

If you come up with some code here is the names of the list, label, service and grid.
list -> mobilelistitem_9
label for weather query -> lookupValue
REST service for API -> GetWeatherInList
Grid in list item for weather -> WxGridTest

Hope this makes sense?


Loop a REST weather service through list

Posted: Thu Apr 21, 2016 5:30 pm
by Serhii Kulibaba

You are right, it is better to run these services in the loop and write their responses to the storage variables, which you can use in the mapping after that.
Please look at this example how to run services in the JavaScript: https://devcenter.appery.io/documenta...
and how to save service's response to the storage variable: https://devcenter.appery.io/documenta...